From 70949986380fa2d11f7bc4f5b85f26a945fdd80b Mon Sep 17 00:00:00 2001 From: Facundo Olano Date: Wed, 21 Feb 2024 18:41:03 -0300 Subject: [PATCH] Outline docs site (#11) * add src_path to template metadata * tweak init files * add docs site with initial layout * add some tweaks to make default layouts more consistent * index tweaks * more layout * stub tutorial entries * add output in docs index * fix footer padding * change listening for serving * simplify submenu * remove inline styles --- README.md | 2 +- commands/commands.go | 2 +- commands/initfiles/includes/nav.html | 11 + commands/initfiles/includes/post_preview.html | 2 +- commands/initfiles/layouts/default.html | 12 +- commands/initfiles/layouts/post.html | 4 - commands/initfiles/src/assets/css/main.css | 8 +- commands/serve.go | 4 +- docs/.gitignore | 3 + docs/README.md | 4 + docs/config.yml | 3 + docs/includes/nav.html | 12 + docs/includes/post_preview.html | 14 + docs/layouts/base.html | 64 +++++ docs/layouts/default.html | 9 + docs/layouts/post.html | 15 ++ docs/src/assets/css/main.css | 246 ++++++++++++++++++ docs/src/blog/goodbye-markdown.md | 13 + docs/src/blog/hello-org.org | 22 ++ docs/src/blog/index.html | 14 + docs/src/blog/tags.html | 16 ++ docs/src/docs/index.html | 15 ++ docs/src/feed.xml | 35 +++ docs/src/index.html | 63 +++++ docs/src/tutorial/building-and-deploying.org | 11 + docs/src/tutorial/creating-a-site.org | 11 + docs/src/tutorial/getting-started.org | 11 + docs/src/tutorial/index.html | 12 + docs/src/tutorial/posts-and-pages.org | 11 + site/site.go | 2 + 30 files changed, 625 insertions(+), 26 deletions(-) create mode 100644 commands/initfiles/includes/nav.html create mode 100644 docs/.gitignore create mode 100755 docs/README.md create mode 100755 docs/config.yml create mode 100644 docs/includes/nav.html create mode 100644 docs/includes/post_preview.html create mode 100644 docs/layouts/base.html create mode 100644 docs/layouts/default.html create mode 100644 docs/layouts/post.html create mode 100644 docs/src/assets/css/main.css create mode 100644 docs/src/blog/goodbye-markdown.md create mode 100644 docs/src/blog/hello-org.org create mode 100644 docs/src/blog/index.html create mode 100644 docs/src/blog/tags.html create mode 100644 docs/src/docs/index.html create mode 100644 docs/src/feed.xml create mode 100644 docs/src/index.html create mode 100755 docs/src/tutorial/building-and-deploying.org create mode 100755 docs/src/tutorial/creating-a-site.org create mode 100755 docs/src/tutorial/getting-started.org create mode 100644 docs/src/tutorial/index.html create mode 100755 docs/src/tutorial/posts-and-pages.org diff --git a/README.md b/README.md index 63b82cd..c7a32bd 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ wrote target/blog/hello-org.html wrote target/blog/index.html wrote target/index.html wrote target/blog/tags.html -server listening at http://localhost:4001 +serving at http://localhost:4001 ``` The site is renders the files found at `src/` in the `target/` directory. diff --git a/commands/commands.go b/commands/commands.go index dadd278..4ffe6ef 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -143,7 +143,7 @@ func Post(root string, title string) error { if err := os.WriteFile(path, []byte(content), FILE_RW_MODE); err != nil { return err } - fmt.Println("added draft", path) + fmt.Println("added", path) return nil } diff --git a/commands/initfiles/includes/nav.html b/commands/initfiles/includes/nav.html new file mode 100644 index 0000000..9c8c6a4 --- /dev/null +++ b/commands/initfiles/includes/nav.html @@ -0,0 +1,11 @@ + diff --git a/commands/initfiles/includes/post_preview.html b/commands/initfiles/includes/post_preview.html index 7ea5ad1..f2d7cf5 100644 --- a/commands/initfiles/includes/post_preview.html +++ b/commands/initfiles/includes/post_preview.html @@ -1,7 +1,7 @@
{{ post.date | date: "%Y-%m-%d" }}
- {{ post.title }} + {{ post.title }} {% if post.favorite %} {% endif %} diff --git a/commands/initfiles/layouts/default.html b/commands/initfiles/layouts/default.html index 7b10544..811033b 100644 --- a/commands/initfiles/layouts/default.html +++ b/commands/initfiles/layouts/default.html @@ -1,17 +1,7 @@ --- layout: base --- - +{% include nav.html %}
{% if page.title %}

{{page.title}}

{% endif %} diff --git a/commands/initfiles/layouts/post.html b/commands/initfiles/layouts/post.html index 81cc4bb..1bf25bc 100644 --- a/commands/initfiles/layouts/post.html +++ b/commands/initfiles/layouts/post.html @@ -1,10 +1,6 @@ --- layout: base --- -
diff --git a/commands/initfiles/src/assets/css/main.css b/commands/initfiles/src/assets/css/main.css index a0c6e6d..3007858 100644 --- a/commands/initfiles/src/assets/css/main.css +++ b/commands/initfiles/src/assets/css/main.css @@ -17,7 +17,7 @@ body { } .footer { - padding-top: 2rem; + padding: 2rem 0 1rem; margin-top: auto; } @@ -86,7 +86,7 @@ article.post { hr { border: 0; - border-top:1px solid; + border-top:1px solid lightgray; } /* tweaks for post content style */ @@ -103,10 +103,6 @@ img.cover-img { margin-bottom: -2rem; } -.layout-post hr { - border: 1px solid silver; -} - .layout-post { hyphens: auto; text-align: justify; diff --git a/commands/serve.go b/commands/serve.go index 11d8f83..bb12068 100644 --- a/commands/serve.go +++ b/commands/serve.go @@ -42,7 +42,7 @@ func Serve(rootDir string) error { } addr := fmt.Sprintf("%s:%d", config.ServerHost, config.ServerPort) - fmt.Printf("server listening at http://%s\n", addr) + fmt.Printf("serving at http://%s\n", addr) return http.ListenAndServe(addr, nil) } @@ -112,7 +112,7 @@ func setupWatcher(config *config.Config) (*fsnotify.Watcher, *EventBroker, error } broker.publish("rebuild") - fmt.Println("done\nserver listening at", config.SiteUrl) + fmt.Println("done\nserving at", config.SiteUrl) case err, ok := <-watcher.Errors: if !ok { diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..228c813 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,3 @@ +target +.DS_Store + diff --git a/docs/README.md b/docs/README.md new file mode 100755 index 0000000..b47ca31 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,4 @@ + +# jorge + +A jorge blog by Facundo Olano. diff --git a/docs/config.yml b/docs/config.yml new file mode 100755 index 0000000..1a92309 --- /dev/null +++ b/docs/config.yml @@ -0,0 +1,3 @@ +name: "jorge" +author: "Facundo Olano" +url: "https://jorge.olano.dev" diff --git a/docs/includes/nav.html b/docs/includes/nav.html new file mode 100644 index 0000000..de11ef3 --- /dev/null +++ b/docs/includes/nav.html @@ -0,0 +1,12 @@ + diff --git a/docs/includes/post_preview.html b/docs/includes/post_preview.html new file mode 100644 index 0000000..142a9c9 --- /dev/null +++ b/docs/includes/post_preview.html @@ -0,0 +1,14 @@ +
+ {% if post.date %}{{ post.date | date: "%Y-%m-%d" }}{% endif %} +
+ {{ post.title }} + + {% if post.favorite %} {% endif %} + + {% for tag in post.tags %} + #{{tag}} + {% endfor %} + + +
+
diff --git a/docs/layouts/base.html b/docs/layouts/base.html new file mode 100644 index 0000000..21e14d1 --- /dev/null +++ b/docs/layouts/base.html @@ -0,0 +1,64 @@ +--- +--- + + + + + + {% if page.title %} + {{page.head_title|default: page.title }} | {{ site.config.name }} + {% else %} + {{ site.config.name }} + {% endif %} + + + + + + + + {% if page.title %} + + + {% endif %} + + {% if page.excerpt %} + + + + {% endif %} + + {% if page.layout == "post" %} + + + + + {% else %} + + + + {% endif %} + + {% if page.image != "" %} + + + {% endif %} + + + + {{ content }} + + + + diff --git a/docs/layouts/default.html b/docs/layouts/default.html new file mode 100644 index 0000000..ce70f2c --- /dev/null +++ b/docs/layouts/default.html @@ -0,0 +1,9 @@ +--- +layout: base +--- +{% include nav.html %} +
+ {% if page.title %}

{{page.title}}

{% endif %} + {{ content }} +
+
diff --git a/docs/layouts/post.html b/docs/layouts/post.html new file mode 100644 index 0000000..86bfeb5 --- /dev/null +++ b/docs/layouts/post.html @@ -0,0 +1,15 @@ +--- +layout: base +--- +{% include nav.html %} + +
+
+

{{ page.title }}

+ {% if page.subtitle %}

{{ page.subtitle }}

{% endif %} + {% if page.cover-img %} + + {% endif %} +
+ {{ content }} +
diff --git a/docs/src/assets/css/main.css b/docs/src/assets/css/main.css new file mode 100644 index 0000000..cea7a7d --- /dev/null +++ b/docs/src/assets/css/main.css @@ -0,0 +1,246 @@ +html { + color-scheme: light dark; + overflow-y: scroll; +} + +body { + max-width: 45em; + margin: 0 auto; + padding: 0 1rem; + width: auto; + font-family: Tahoma, Verdana, Arial, sans-serif; + line-height: 1.5; + + height: 100vh; + display: flex; + flex-direction: column; +} + +.footer { + padding: 2rem 0 1rem; + margin-top: auto; +} + +@media screen and (max-width: 480px) { + .hidden-mobile { + display: none + } +} + +nav { + margin: 1rem 0; + line-height: 1.8; + border-bottom: 1px solid; + display: flex; +} +.nav-right { + margin-left: auto; +} +nav a:not(:last-child) { + margin-right: 1rem +} +nav a:hover { + text-decoration: none; +} + +li { + line-height: 1.6; +} + +li:not(:last-child) { + padding-bottom: .75rem; +} + +a, a:visited { + color: LinkText; + text-decoration: none; +} +a:hover { + text-decoration: underline +} + +a.title { + color: unset!important; + padding-right: .25rem; +} + +.footer, .footer a, .date, .tags, .tags a { + color: silver; +} +.date { + padding-right: .5rem; + white-space: nowrap; +} +.tags { + display: inline-block; +} + +article.post { + display: flex; + padding-bottom: .5rem; +} + +.center-block { + text-align: center; +} + +hr { + border: 0; + border-top:1px solid lightgray; +} + +/* tweaks for post content style */ +.layout-post img { + max-width: 75%; + max-height: 400px; +} + +img.cover-img { + width: 100%; + max-width: 100%; + max-height: 200px; + object-fit: cover; + margin-bottom: -2rem; +} + +.layout-post { + hyphens: auto; + text-align: justify; + font-size: 1.15rem; + line-height: 1.6; + + -moz-osx-font-smoothing: grayscale; + -webkit-font-smoothing: antialiased !important; + -moz-font-smoothing: antialiased !important; + text-rendering: optimizelegibility !important; + letter-spacing: .03em; +} + +.layout-post .title { + hyphens:none; +} + +.layout-post header { + margin: 3rem 0 5rem; + text-align: left; +} + +.layout-post header.with-cover { + margin-top: -0.5rem; +} + +.src pre { + font-size: 1rem; + overflow-x: auto; + line-height: 1.5; + padding-left: 1rem +} + +blockquote { + border-left: 2px solid whitesmoke; + padding-left: 1rem; +} + +.layout-post p.verse { + text-align: right; +} + +.layout-post p { + line-height: 1.8; + margin-bottom: 1.5rem; +} + +.layout-post p + h2 { + padding-top: 1.5rem; +} + +.layout-post .center-block { + margin: 2rem 0; +} + +/* override in mobile devices for more compact text */ +@media screen and (max-width: 768px) { + .layout-post { + font-size: 1rem; + line-height: 1.2; + letter-spacing: unset; + hyphens: none; + text-align: left; + } + + .layout-post p { + margin: 0 0 1rem 0; + line-height: 1.7; + } + + .layout-post p + p { + text-indent: 0; + } + + .layout-post img { + max-width: 100%; + } +} + +table { + width: 100%; + border-collapse: collapse; + +} + +table tr { + border-bottom: 1px solid #ddd; +} + +td, th { + padding: .5rem; +} + + +hr.footnotes-separatator { + display:none; +} + +/* makes footnote number and text display in the same line */ +.footnote-definition { + display: block; + vertical-align: top; + margin-bottom: .4rem; +} +.footnote-body, .footnote-body p { + display: inline; +} + +/* These control the expand/collapse behavior of the tags page */ +details summary { + list-style: none; + cursor: pointer; +} + +details summary h3::after { + content: "[+]"; + font-size: small; + font-weight: normal; + font-family: monospace; + vertical-align: middle; +} + +details[open] summary h3::after { + content: "[-]" +} + +details > summary::-webkit-details-marker { + display: none; +} + +.silver { + color: silver; +} + +code.index-sample { + display: inline-block; +} + +code.index-sample pre { + text-align: left; +} diff --git a/docs/src/blog/goodbye-markdown.md b/docs/src/blog/goodbye-markdown.md new file mode 100644 index 0000000..60509d3 --- /dev/null +++ b/docs/src/blog/goodbye-markdown.md @@ -0,0 +1,13 @@ +--- +title: Goodbye Markdown... +tags: [blog] +date: 2024-02-16 +layout: post +--- + +## For the record + +For the record, even though it has *org* in the name, jorge can also render markdown, +thanks to [goldmark](https://github.com/yuin/goldmark/). + +[Next time](./hello-org), I'll talk about org-mode posts. diff --git a/docs/src/blog/hello-org.org b/docs/src/blog/hello-org.org new file mode 100644 index 0000000..456bca2 --- /dev/null +++ b/docs/src/blog/hello-org.org @@ -0,0 +1,22 @@ +--- +title: Hello Org! +subtitle: Writing posts with org-mode syntax +tags: [blog, emacs] +date: 2024-02-17 +layout: post +--- +#+OPTIONS: toc:nil num:nil + +** Indeed + +This post was originally written with org-mode syntax, instead of [[file:goodbye-markdown][markdown]]. + +As you can see, /italics/ and *bold* render as expected, and you can even use footnotes[fn:1]. + +All of this is powered by [[https://github.com/niklasfasching/go-org][go-org]], btw[fn:2]. + +** Notes + +[fn:1] See? + +[fn:2] And another one footnote, to stay on the safe side. diff --git a/docs/src/blog/index.html b/docs/src/blog/index.html new file mode 100644 index 0000000..f5ce392 --- /dev/null +++ b/docs/src/blog/index.html @@ -0,0 +1,14 @@ +--- +layout: default +title: Devlog +--- + +{% assign posts_by_year = site.posts | group_by_exp:"post", "post.date | date: '%Y'" %} +{% for year in posts_by_year %} + {% unless forloop.first%} +
+ {% endunless %} + {% for post in year.items %} + {% include post_preview.html %} + {% endfor %} +{% endfor %} diff --git a/docs/src/blog/tags.html b/docs/src/blog/tags.html new file mode 100644 index 0000000..c967018 --- /dev/null +++ b/docs/src/blog/tags.html @@ -0,0 +1,16 @@ +--- +layout: default +title: Tags +--- + +{% for tag in site.tags %} +
+ +

#{{tag[0]}}

+
+ + {% for post in tag[1] %} + {% include post_preview.html %} + {% endfor %} +
+{% endfor %} diff --git a/docs/src/docs/index.html b/docs/src/docs/index.html new file mode 100644 index 0000000..8b23380 --- /dev/null +++ b/docs/src/docs/index.html @@ -0,0 +1,15 @@ +--- +layout: default +title: Devlog +--- + +Comming soon! + +
    + {% for page in site.pages|where:"dir", "/docs"|sort:"index" %} +
  • + {{ page.title }} +
  • + {% endfor %} +
+
diff --git a/docs/src/feed.xml b/docs/src/feed.xml new file mode 100644 index 0000000..d61631d --- /dev/null +++ b/docs/src/feed.xml @@ -0,0 +1,35 @@ +--- +--- + + + jorge + + + {{ "now" | date: "%Y-%m-%d %H:%M" }} + {{ page.url | absolute_url}} + {{ site.config.name }} + + {{ site.config.author }} + + {% for post in site.posts limit:10 %} + + {% assign post_title = post.title | strip_html | normalize_whitespace | xml_escape %} + {{ post.title }} + + {{ post.date | date: "%Y-%m-%d %H:%M" }} + {{ post.date | date: "%Y-%m-%d %H:%M" }} + {{ post.url | absolute_url }} + + {{ post.author | default:site.config.author }} + + {% for tag in post.tags %} + + {% endfor %} + + {% if post.image %} + + + {% endif %} + + {% endfor %} + diff --git a/docs/src/index.html b/docs/src/index.html new file mode 100644 index 0000000..e7fb775 --- /dev/null +++ b/docs/src/index.html @@ -0,0 +1,63 @@ +--- +layout: base +--- + +
+
+
+
+

jorge is a personal (small + opinionated) site generator

+
+ +
+$ jorge init .
+> site name: My Blog
+> site url: https://myblog.olano.dev
+> author: Facundo
+  added layouts/base.html
+  added layouts/post.html
+  added src/assets/css/main.css
+  added src/blog/hello-org.org
+  added src/blog/index.html
+  added src/blog/tags.html
+  added src/feed.xml
+  added src/index.html
+$ jorge post "Hello World!"
+  added src/blog/my-first-post.org
+$ jorge serve
+  serving at http://localhost:4001
+        
+
+

Open source, Inspired by Jekyll, with org-mode and Markdown support.

+
+
+ +
+
+

Tutorial

+
    +{% for page in site.pages|where:"dir", "/tutorial"|sort:"index" %} +
  1. + {{ page.title }} +
  2. +{% endfor %} +
+ +

Devlog

+ +{% for post in site.posts limit:3 %} +{% include post_preview.html %} +{% endfor %} + +

See the full blog archive or subscribe to the feed.

+ +

Docs

+Coming soon! +
    + {% for page in site.pages|where:"dir", "/docs"|sort:"index" %} +
  • + {{ page.title }} +
  • + {% endfor %} +
+
diff --git a/docs/src/tutorial/building-and-deploying.org b/docs/src/tutorial/building-and-deploying.org new file mode 100755 index 0000000..5b0eb85 --- /dev/null +++ b/docs/src/tutorial/building-and-deploying.org @@ -0,0 +1,11 @@ +--- +title: Building and deploying +layout: post +lang: en +tags: [tutorial] +index: 4 +--- +#+OPTIONS: toc:nil num:nil +#+LANGUAGE: en + +Coming soon! diff --git a/docs/src/tutorial/creating-a-site.org b/docs/src/tutorial/creating-a-site.org new file mode 100755 index 0000000..079ba06 --- /dev/null +++ b/docs/src/tutorial/creating-a-site.org @@ -0,0 +1,11 @@ +--- +title: Creating a new site +layout: post +lang: en +tags: [tutorial] +index: 2 +--- +#+OPTIONS: toc:nil num:nil +#+LANGUAGE: en + +Coming soon! diff --git a/docs/src/tutorial/getting-started.org b/docs/src/tutorial/getting-started.org new file mode 100755 index 0000000..573b1fa --- /dev/null +++ b/docs/src/tutorial/getting-started.org @@ -0,0 +1,11 @@ +--- +title: Getting started +layout: post +lang: en +tags: [tutorial] +index: 1 +--- +#+OPTIONS: toc:nil num:nil +#+LANGUAGE: en + +Coming soon! diff --git a/docs/src/tutorial/index.html b/docs/src/tutorial/index.html new file mode 100644 index 0000000..9e05df9 --- /dev/null +++ b/docs/src/tutorial/index.html @@ -0,0 +1,12 @@ +--- +layout: default +title: Tutorial +--- + +
    + {% for page in site.pages|where:"dir", "/tutorial"|sort:"index" %} +
  1. + {{ page.title }} +
  2. + {% endfor %} +
diff --git a/docs/src/tutorial/posts-and-pages.org b/docs/src/tutorial/posts-and-pages.org new file mode 100755 index 0000000..76a2a04 --- /dev/null +++ b/docs/src/tutorial/posts-and-pages.org @@ -0,0 +1,11 @@ +--- +title: Posts and pages +layout: post +lang: en +tags: [tutorial] +index: 3 +--- +#+OPTIONS: toc:nil num:nil +#+LANGUAGE: en + +Coming soon! diff --git a/site/site.go b/site/site.go index 255d480..2334b4a 100644 --- a/site/site.go +++ b/site/site.go @@ -137,7 +137,9 @@ func (site *Site) loadTemplates() error { // set site related (?) metadata. Not sure if this should go elsewhere relPath, _ := filepath.Rel(site.Config.SrcDir, path) + srcPath, _ := filepath.Rel(site.Config.RootDir, path) relPath = strings.TrimSuffix(relPath, filepath.Ext(relPath)) + templ.Ext() + templ.Metadata["src_path"] = srcPath templ.Metadata["path"] = relPath templ.Metadata["url"] = "/" + strings.TrimSuffix(strings.TrimSuffix(relPath, "index.html"), ".html") templ.Metadata["dir"] = "/" + filepath.Dir(relPath)