diff --git a/articles/introduction.md b/articles/introduction.md index db25393f8e82bdae7a1dc9f7a779d36c9048a4d7..221258b975335736ddb331fa0f3d20d269d75495 100644 --- a/articles/introduction.md +++ b/articles/introduction.md @@ -1,18 +1,17 @@ +++ title = "Introduction" -summary = "An introduction of my blog" +summary = "An introduction of `blog`" date = 2024-02-17 category = "Miscellaneous" +++ -# Hello and welcome to my blog! +# Hello and welcome to blog! -My blog consists of a home-rolled SSG. +`blog` is a simple static blog generator! Truly cutting edge, I know. Never seen one of these before, have you? -This article mainly exists as a "kitchen sink" to check out style changes when I make them. - +[tl;dr](#tldr) ```go package main @@ -27,9 +26,18 @@ Things it can do: - [x] Render code :pencil: -- [ ] Fill the void[^1] :black_circle: +- [ ] Fill the void :black_circle: + +## Why was blog created? -`blog` parses some articles (in markdown format), renders them, and pushes them to an output directory. +~~Because I needed a specific thing that other generators couldn't give me. Blog is up to 1000 times faster than \!!!~~ + +Because I wanted to, like many other projects in this space. Blog is designed to be simple (to me) with enough flexibility for someone else to use without +cursing at me (too much). + +--- + +`blog` parses some templates and articles (in markdown format), renders them, and pushes them to an output directory. It can handle emoji :bomb: and code highlighting: @@ -38,9 +46,19 @@ def main(): print("Hello, blog!") ``` -||Is written in Go|Has "Go" in the name| -|---|---|---| -|`blog`|:heavy_check_mark:|:x:| -|`hugo`|:heavy_check_mark:|:heavy_check_mark:| + +## tl;dr + +Check out the [example](https://git.jolheiser.com/blog/tree/main/_example). + +The `articles` dir contains a list of articles, namely this one. + +The `templates` dir contains a handful of [go templates](https://pkg.go.dev/html/template) that make up how to render the blog. +- `article.tmpl` is a template for an individual article (this page). +- `index.tmpl` is the main blog overview. +- `base.tmpl` is a collection of [defined blocks](https://pkg.go.dev/text/template#hdr-Nested_template_definitions) +that are then re-used in `index.tmpl` and `article.tmpl` to create a cohesive look-and-feel. -[^1]: Blogs don't usually fill voids, so this might be normal. +Finally, `config.yaml` (which can also be TOML if desired) allows you to not have to continuously re-type all the flags to define things like your +`--article-dir`, `--template-dir`, or `--out`. + diff --git a/main.go b/main.go index 747475235f2d618a6f1748d5f4703db08779e4a3..699fc9c7e531aab231d5297efcfa4f50cdf0d5b5 100644 --- a/main.go +++ b/main.go @@ -16,12 +16,8 @@ "github.com/alecthomas/chroma/v2/styles" ) -var ( - //go:embed articles/* - articleFS embed.FS - //go:embed static/* - staticFS embed.FS -) +//go:embed articles/* +var articleFS embed.FS func maine() error { fs := flag.NewFlagSet("blog", flag.ExitOnError) @@ -61,7 +57,8 @@ if err := writeCSS(*outFlag); err != nil { return err } - if err := copyStatic(*outFlag); err != nil { + sakuraDst := filepath.Join(*outFlag, "sakura.css") + if err := copyFile(sakuraDst, "sakura.css"); err != nil { return err } @@ -76,7 +73,6 @@ return err } if *serveFlag { - fmt.Println("http://localhost:8080") http.Handle("/", http.FileServer(http.Dir("out"))) http.ListenAndServe(":8080", nil) } @@ -106,7 +102,7 @@ return err } defer fi.Close() - if err := CSS.WriteCSS(fi, styles.Get("catppuccin-latte")); err != nil { + if err := CSS.WriteCSS(fi, styles.Get("catpuccin-latte")); err != nil { return err } fi.WriteString("@media (prefers-color-scheme: dark) {") @@ -114,37 +110,6 @@ if err := CSS.WriteCSS(fi, styles.Get("catppuccin-mocha")); err != nil { return err } fi.WriteString("}") - return nil -} - -func copyStatic(out string) error { - files, err := staticFS.ReadDir("static") - if err != nil { - return err - } - for _, file := range files { - if err := func() error { - dstFi, err := os.Create(filepath.Join(out, file.Name())) - if err != nil { - return err - } - defer dstFi.Close() - - srcFi, err := staticFS.Open("static/" + file.Name()) - if err != nil { - return err - } - defer srcFi.Close() - - if _, err := io.Copy(dstFi, srcFi); err != nil { - return err - } - - return nil - }(); err != nil { - return err - } - } return nil } diff --git a/static/jolheiser.css b/static/jolheiser.css deleted file mode 100644 index cc1c1a8066352fcf041bc042867a2a15830ab55e..0000000000000000000000000000000000000000 --- a/static/jolheiser.css +++ /dev/null @@ -1,8 +0,0 @@ -code { - border-radius: 5px; -} - -.chroma { - background-color: var(--bg-alt); - border-radius: 5px; -} diff --git a/static/sakura.css b/sakura.css rename from static/sakura.css rename to sakura.css diff --git a/templates.go b/templates.go index 2b72afdd54e37dbe3a42b85a37f0f2234a7b21cd..8af412b693c9a8150dd0e116a5d93f31a59570d1 100644 --- a/templates.go +++ b/templates.go @@ -106,7 +106,6 @@ html.WithUnsafe(), ), goldmark.WithExtensions( extension.GFM, - extension.Footnote, meta.Meta, emoji.Emoji, highlighting.NewHighlighting( diff --git a/templates.templ b/templates.templ index 68077b6bf65407a4afcf6f0564fdd67e1661d34b..d974b5833560129812c609934c2a97b293f617fc 100644 --- a/templates.templ +++ b/templates.templ @@ -11,7 +11,6 @@ - { children... } @@ -38,10 +37,7 @@ templ ArticleTemplate(article Article) { @baseTemplate(article.Title, article.Summary) {

{ article.Title }

-
-

{ article.Category }

-

{ article.Date.Format("Mon, 02 Jan 2006") }

-
+

{ article.Date.Format("01/02/2006") }

@templ.Raw(article.Content)
} diff --git a/templates_templ.go b/templates_templ.go index 4a486d19e9f7315420f196c5883d7f5e49458522..0ee91ec438bb7e3ec1045cac3e9e52db9e72d059 100644 --- a/templates_templ.go +++ b/templates_templ.go @@ -48,7 +48,7 @@ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(description)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -181,25 +181,16 @@ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var11 string = article.Category + var templ_7745c5c3_Var11 string = article.Date.Format("01/02/2006") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var12 string = article.Date.Format("Mon, 02 Jan 2006") - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }