diff options
author | sanine <sanine.not@pm.me> | 2023-01-12 17:29:28 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-01-12 17:29:28 -0600 |
commit | f9f8a3206298363059601f6c389584426962e5e4 (patch) | |
tree | b0ed2fd393a1064c01aabdce548e9f84215a8c57 | |
parent | 655cd79991ec9204afb9f5acf52495c13af14d25 (diff) |
wrong branch :c
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | config.lua | 12 | ||||
-rw-r--r-- | data/index.md | 30 | ||||
-rw-r--r-- | layouts/base.lua | 63 | ||||
-rw-r--r-- | layouts/blog.lua | 8 | ||||
-rw-r--r-- | plugins/navigation.lua | 0 | ||||
-rw-r--r-- | plugins/toolkit.lua | 42 | ||||
-rwxr-xr-x | serve-http.sh | 19 | ||||
-rw-r--r-- | server/go.mod | 10 | ||||
-rw-r--r-- | server/go.sum | 17 | ||||
-rw-r--r-- | server/main.go | 48 | ||||
-rw-r--r-- | server/md-page.go | 95 | ||||
-rw-r--r-- | site_root/about.lua (renamed from data/about.lua) | 0 | ||||
-rw-r--r-- | site_root/blog/03-remote_full_system_encryption_with_arch.lua (renamed from data/blog/03-remote_full_system_encryption_with_arch.lua) | 0 | ||||
-rw-r--r-- | site_root/blog/announcing_honeysuckle.lua (renamed from data/blog/announcing_honeysuckle.lua) | 0 | ||||
-rw-r--r-- | site_root/blog/refactor-argent.lua (renamed from data/blog/refactor-argent.lua) | 0 | ||||
-rw-r--r-- | site_root/cgit.css (renamed from data/cgit.css) | 0 | ||||
-rw-r--r-- | site_root/favicon.svg (renamed from data/favicon.svg) | 0 | ||||
-rw-r--r-- | site_root/index.lua (renamed from data/index.lua) | 0 | ||||
-rw-r--r-- | site_root/projects/index.lua (renamed from data/projects/index.lua) | 0 | ||||
-rw-r--r-- | site_root/style.css (renamed from data/style.css) | 0 |
21 files changed, 144 insertions, 201 deletions
@@ -1,4 +1,3 @@ *~ public/ publish.sh -server/sanine.net-server diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..1f797ce --- /dev/null +++ b/config.lua @@ -0,0 +1,12 @@ +return { + site_name = 'sanine.net', + site_address = 'https://sanine.net/', + site_directory = 'site_root', + + layout_directory = 'layouts', + plugin_directory = 'plugins', + + exclude = { '.*~' }, + + rss_include = { 'blog' }, +} diff --git a/data/index.md b/data/index.md deleted file mode 100644 index c419830..0000000 --- a/data/index.md +++ /dev/null @@ -1,30 +0,0 @@ -local tk = require 'toolkit' - -function get_blog_links() - local links = '<ul>\n' - local pages = tk.pages('blog/') - table.sort(pages, function(a, b) return a.date > b.date end) - for _, page in pairs(pages) do - links = links .. - string.format('<li><a href="%s">[%s] %s</a></li>\n', page.href, page.date, page.title) - end - return links..'</ul>' -end - - -local md = string.format([[ -home -==== - -welcome to sanine.net! - -%s - -[subscribe via rss](/rss.xml) -]], get_blog_links()) - -return { - title='home', - layout='base', - markdown=md, -} diff --git a/layouts/base.lua b/layouts/base.lua new file mode 100644 index 0000000..1c585d7 --- /dev/null +++ b/layouts/base.lua @@ -0,0 +1,63 @@ +local navigation_table = { + {'home', '/index.html'}, + {'projects', '/projects/'}, + {'git', '/git'}, + {'about', '/about.html'}, +} + +local navlinks = '' + +for _, link in pairs(navigation_table) do + navlinks = navlinks .. + string.format('<a href="%s">%s</a> ', link[2], link[1]) +end +navlinks = string.sub(navlinks, 1, -4) + +local navigation = string.format('<div id="navigation"><pre>%s</pre></div>', navlinks) + +return function(html, page_tbl) + local html = string.gsub( + html, + '<h1>(.-)</h1>', + function(s) + return string.format( + '<h1>%s</h1>%s</br>', + s, string.rep('=', string.len(s)) + ) + end + ) + + html = string.gsub( + html, + '<h2>(.-)</h2>', + function(s) + return string.format( + '<h2>%s</h2>%s</br>', + s, string.rep('-', string.len(s)) + ) + end + ) + + local fmt = [[ +<!doctype html> + <html> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <link rel="icon" type="image/svg+xml" href="/favicon.svg"> + <title>%s</title> + <link rel="stylesheet" href="/style.css"> + </html> + <body> + <div id="content"> + %s + %s + </div> + </body> +</html> +]] +return string.format( + fmt, + string.format('%s | %s', page_tbl.title, argent.config.site_name), + navigation, + html) +end diff --git a/layouts/blog.lua b/layouts/blog.lua new file mode 100644 index 0000000..eaed8a2 --- /dev/null +++ b/layouts/blog.lua @@ -0,0 +1,8 @@ +local base = require('layouts.base') + +return function(html, page_tbl) + local html = string.format( + '<h1>%s</h1>\n\n%s', + page_tbl.title, html) + return base(html, page_tbl) +end diff --git a/plugins/navigation.lua b/plugins/navigation.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/navigation.lua diff --git a/plugins/toolkit.lua b/plugins/toolkit.lua new file mode 100644 index 0000000..e5f162a --- /dev/null +++ b/plugins/toolkit.lua @@ -0,0 +1,42 @@ +local toolkit = {} + +toolkit.file_iterator = function(directory) + local _, files = argent.scanDirectory(directory) + local i = 0 + local n = table.getn(files) + return function() + i = i+1 + if i<=n then return files[i] end + end +end + + +toolkit.basename = function(filename) + return string.gsub(filename, '%.lua$', '') +end + + +local function extract_page(file) + if not string.match(file, '%.lua$') then return nil end + + local success, result = pcall(loadfile(file), 0, 1) + if not success then return nil end + return result +end + +toolkit.pages = function(directory) + page_array = {} + local path = argent.config.site_directory..directory + for file in toolkit.file_iterator(path) do + local page = extract_page(path..file) + if page then + page.href = '/'..directory..toolkit.basename(file)..'.html' + table.insert(page_array, page) + end + end + + return page_array +end + + +return toolkit diff --git a/serve-http.sh b/serve-http.sh new file mode 100755 index 0000000..874b586 --- /dev/null +++ b/serve-http.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# this script is for previewing site changes ONLY!! it should not be used to +# actually serve a site. use apache or nginx or something for that. + +# launch webserver +python3 -m http.server --directory public/ & +server_pid="$!" +echo "server launched with PID $server_pid" + +# kill server on exit +trap "kill $server_pid && echo && echo \"bye!\"" EXIT + +# rebuild on file changes (inotifywait is from inotify-tools) +while inotifywait -qr --event modify .; do + echo "rebuilding site..." + argent + echo "done." +done diff --git a/server/go.mod b/server/go.mod deleted file mode 100644 index 6328a03..0000000 --- a/server/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module sanine.net/sanine.net-server - -go 1.19 - -require ( - github.com/russross/blackfriday/v2 v2.1.0 - github.com/sirupsen/logrus v1.9.0 -) - -require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect diff --git a/server/go.sum b/server/go.sum deleted file mode 100644 index 900e85f..0000000 --- a/server/go.sum +++ /dev/null @@ -1,17 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/server/main.go b/server/main.go deleted file mode 100644 index 63aadb5..0000000 --- a/server/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "flag" - "path/filepath" - log "github.com/sirupsen/logrus" -) - - -func main() { - log.SetFormatter(&log.TextFormatter{ - FullTimestamp: true, - }); - - pathFlag := flag.String( - "path", "data", "the path to load site data from", - ); - addrFlag := flag.String( - "addr", "127.0.0.1:8080", "the address to serve from", - ); - flag.Parse(); - log.Infof("data path: %v", *pathFlag); - log.Infof("serving from %v", *addrFlag); - - mux := http.NewServeMux() - mux.HandleFunc("/ip", func(w http.ResponseWriter, req *http.Request) { - fmt.Fprintf(w, "%v", req.RemoteAddr); - }); - mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { - if req.URL.Path != "/" { - path := filepath.Join(*pathFlag, req.URL.Path); - Serve(w, req, path); - } else { - Serve(w, req, filepath.Join(*pathFlag, "index.md")); - } - }); - - server := http.Server{ - Addr: *addrFlag, - Handler: mux, - }; - err := server.ListenAndServe(); - if err != nil { - log.Fatal(err); - } -} diff --git a/server/md-page.go b/server/md-page.go deleted file mode 100644 index 8b378c5..0000000 --- a/server/md-page.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "os" - "strings" - "net/http" - log "github.com/sirupsen/logrus" - md "github.com/russross/blackfriday/v2" -) - - -func ServeForbidden(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(403); - w.Write([]byte("403 forbidden")); -} - - -func ServeNotFound(w http.ResponseWriter, r *http.Request) { - http.NotFound(w, r); -} - - -func RenderMarkdown(path string) ([]byte, error) { - data, err := os.ReadFile(path); - if err != nil { - return []byte{}, err; - } - return md.Run(data), nil; -} - - -func ServeMarkdown(w http.ResponseWriter, r *http.Request, path string) (int, error) { - page, err := RenderMarkdown(path); - if err != nil { - return 404, err; - } - w.WriteHeader(200); - w.Write(page); - return 200, nil; -} - -func ServeFile(w http.ResponseWriter, r *http.Request, path string) (int, error) { - if strings.Contains(r.URL.Path, "..") { - // reject requests with ".." in the URL - return 403, nil; - } - data, err := os.ReadFile(path); - if err != nil { - return 404, err; - } - - w.WriteHeader(200); - w.Write(data); - return 200, nil; -} - - -func IsMarkdown(path string) bool { - return strings.HasSuffix(path, ".md"); -} - - -func Serve(w http.ResponseWriter, r *http.Request, path string) { - var status int; - var err error; - - if IsMarkdown(path) { - // render and serve markdown content - status, err = ServeMarkdown(w, r, path); - } else { - // serve raw file - status, err = ServeFile(w, r, path); - } - - if status == 200 { - log.Infof( - "%v 200\t%v <- %v", - r.Method, r.RemoteAddr, r.URL.Path, - ); - } else { - log.Errorf( - "%v %v\t%v <- %v: %v", - r.Method, status, r.RemoteAddr, r.URL.Path, err, - ); - switch status { - case 403: - ServeForbidden(w, r); - case 404: - ServeNotFound(w, r); - default: - w.WriteHeader(status); - w.Write([]byte("error")); - } - } -} diff --git a/data/about.lua b/site_root/about.lua index 9f87357..9f87357 100644 --- a/data/about.lua +++ b/site_root/about.lua diff --git a/data/blog/03-remote_full_system_encryption_with_arch.lua b/site_root/blog/03-remote_full_system_encryption_with_arch.lua index 43fccfa..43fccfa 100644 --- a/data/blog/03-remote_full_system_encryption_with_arch.lua +++ b/site_root/blog/03-remote_full_system_encryption_with_arch.lua diff --git a/data/blog/announcing_honeysuckle.lua b/site_root/blog/announcing_honeysuckle.lua index f078585..f078585 100644 --- a/data/blog/announcing_honeysuckle.lua +++ b/site_root/blog/announcing_honeysuckle.lua diff --git a/data/blog/refactor-argent.lua b/site_root/blog/refactor-argent.lua index 6b7ca4d..6b7ca4d 100644 --- a/data/blog/refactor-argent.lua +++ b/site_root/blog/refactor-argent.lua diff --git a/data/cgit.css b/site_root/cgit.css index 9242499..9242499 100644 --- a/data/cgit.css +++ b/site_root/cgit.css diff --git a/data/favicon.svg b/site_root/favicon.svg index 142a88c..142a88c 100644 --- a/data/favicon.svg +++ b/site_root/favicon.svg diff --git a/data/index.lua b/site_root/index.lua index c419830..c419830 100644 --- a/data/index.lua +++ b/site_root/index.lua diff --git a/data/projects/index.lua b/site_root/projects/index.lua index d8751b3..d8751b3 100644 --- a/data/projects/index.lua +++ b/site_root/projects/index.lua diff --git a/data/style.css b/site_root/style.css index 897b490..897b490 100644 --- a/data/style.css +++ b/site_root/style.css |