From: Michael D. Lowis Date: Thu, 4 Jun 2020 12:46:53 +0000 (-0400) Subject: added more pages X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e1719d8bafe0c96f2c9e71e45046e895c53c4b21;p=projs%2Fawiki.git added more pages --- diff --git a/awiki.rb b/awiki.rb index 227ccb2..70d3df1 100755 --- a/awiki.rb +++ b/awiki.rb @@ -6,7 +6,6 @@ require 'redcarpet' # TODO: # * Add page attachment mechanism -# * Add edit shortcut # * Add save shortcut # * Add a create method # * Add a delete method @@ -24,12 +23,23 @@ PLANTUML_CMD = "java -jar #{PLANTUML_JAR} -tsvg -pipe" EDIT_SCRIPT = <<-eos eos +def html_path(src) + src.sub(/\.([^.]*)$/, '.html').sub(/^#{PAGES_DIR}/, HTML_DIR) +end + +def page_path(path) + (PAGES_DIR + path).sub(/^\/html\//,'').sub(/\.html$/, ".md") +end + class Page def initialize(src) @markdown = (File.exist?(src) ? File.read(src) : "") @@ -89,6 +99,7 @@ def genallpages() genpage(nil, f, true) end FileUtils.cp_r(Dir.glob("files/*"), HTML_DIR) + gensitemap() end def gensitemap() @@ -107,7 +118,7 @@ end def genpage(path, src, force=false) html = "" - htmlfile = src.sub(/\.([^.]*)$/, '.html').sub(/^#{PAGES_DIR}/, HTML_DIR) + htmlfile = html_path(src) puts "#{src} -> #{htmlfile}" if not FileUtils.uptodate?(htmlfile, [src, VIEW_TEMPLATE]) or force FileUtils.mkdir_p(File.dirname(htmlfile)) @@ -123,9 +134,9 @@ def genpage(path, src, force=false) end def do_post(req, res, path) - page_path = (PAGES_DIR + req.path).sub(/\.html$/, '.md') + page_path = page_path(path) FileUtils.mkdir_p(File.dirname(page_path)) - markup = req.query["markup"].gsub(//,"\n").gsub("\r\n","\n").gsub(/</,"<").gsub(/>/,">") + markup = req.query["markup"].gsub("\r\n","\n").gsub(/</,"<").gsub(/>/,">") File.open(page_path, "wb") {|f| f.write(markup) } res.status = 302 res["Location"] = req.path @@ -139,7 +150,7 @@ end def do_get(req, res, path) if path.end_with?(".html") - page_path = PAGES_DIR + path.sub(/^\/html\//,'').sub(/\.html$/, ".md") + page_path = page_path(path) if (req.query["edit"] == "true") || (not File.exist?(page_path)) do_edit(req, res, path, page_path) else @@ -175,26 +186,27 @@ $markdown = Redcarpet::Markdown.new( # Generate all pages from scratch genallpages() -$server = WEBrick::HTTPServer.new( - :Port => SERVER_PORT, - :SSLEnable => false, - :DocumentRoot => HTML_DIR, - :ServerAlias => 'localhost' -) - -$server.mount_proc '/' do |req, res| - rqtype = req.request_method - path = (req.path.end_with?("/") ? req.path + "index.html" : req.path) - if rqtype == "GET" - do_get(req, res, path) - elsif rqtype == "POST" - do_post(req, res, path) +if ARGV.length > 0 then + $server = WEBrick::HTTPServer.new( + :Port => SERVER_PORT, + :SSLEnable => false, + :DocumentRoot => HTML_DIR, + :ServerAlias => 'localhost' + ) + + $server.mount_proc '/' do |req, res| + rqtype = req.request_method + path = (req.path.end_with?("/") ? req.path + "index.html" : req.path) + if rqtype == "GET" + do_get(req, res, path) + elsif rqtype == "POST" + do_post(req, res, path) + end end -end -trap 'INT' do - $server.shutdown - genallpages() + trap 'INT' do + $server.shutdown + # genallpages() + end + $server.start end -$server.start - diff --git a/config/editor.html.erb b/config/editor.html.erb index 30a3f1e..9c8bca0 100644 --- a/config/editor.html.erb +++ b/config/editor.html.erb @@ -18,7 +18,7 @@ let submit = ()=>{ }; (() => { const keys = { - "Enter": () => !document.execCommand("insertText", false, "\r\n"), + "Enter": () => !document.execCommand("insertText", false, "\n"), "Tab": () => !document.execCommand("insertText", false, " "), }; editor.onkeydown = (ev) => (!!keys[ev.key] ? (keys[ev.key])(ev) : true); diff --git a/config/page.html.erb b/config/page.html.erb index bcdb9ae..e7f638c 100644 --- a/config/page.html.erb +++ b/config/page.html.erb @@ -5,7 +5,7 @@ <%= @site_title + (@page_title.nil? ? "" : " - #{@page_title}") %> - +