My personal website

Rename meta to context

fruno.win 46b547eb 8593078b

verified
+52 -63
+1 -1
gleam.toml
··· 30 30 lustre = ">= 5.4.0 and < 6.0.0" 31 31 gleam_time = ">= 1.6.0 and < 2.0.0" 32 32 simplifile = ">= 2.3.2 and < 3.0.0" 33 - shellout = ">= 1.7.0 and < 2.0.0" 34 33 jot = ">= 8.0.0 and < 9.0.0" 35 34 tom = ">= 2.0.0 and < 3.0.0" 36 35 gleam_javascript = ">= 1.0.0 and < 2.0.0" 36 + envoy = ">= 1.1.0 and < 2.0.0"
+1 -2
manifest.toml
··· 17 17 { name = "jot", version = "8.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "houdini", "splitter"], otp_app = "jot", source = "hex", outer_checksum = "CCE11C8904B129CC9DA3A293B645884B91C96D252183F6DBCAEFA8F2587CAEFD" }, 18 18 { name = "lustre", version = "5.4.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib", "houdini"], otp_app = "lustre", source = "hex", outer_checksum = "40E097BABCE65FB7C460C073078611F7F5802EB07E1A9BFB5C229F71B60F8E50" }, 19 19 { name = "lustre_ssg", version = "0.12.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_regexp", "gleam_stdlib", "jot", "lustre", "simplifile", "temporary", "tom"], source = "git", repo = "https://github.com/fruno-bulax/lustre_ssg", commit = "6c132bd34ab75a1144d31c0f896cab0e3cbf80fc" }, 20 - { name = "shellout", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "1BDC03438FEB97A6AF3E396F4ABEB32BECF20DF2452EC9A8C0ACEB7BDDF70B14" }, 21 20 { name = "simplifile", version = "2.3.2", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "E049B4DACD4D206D87843BCF4C775A50AE0F50A52031A2FFB40C9ED07D6EC70A" }, 22 21 { name = "splitter", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "splitter", source = "hex", outer_checksum = "3DFD6B6C49E61EDAF6F7B27A42054A17CFF6CA2135FF553D0CB61C234D281DD0" }, 23 22 { name = "temporary", version = "1.0.0", build_tools = ["gleam"], requirements = ["envoy", "exception", "filepath", "gleam_crypto", "gleam_stdlib", "simplifile"], otp_app = "temporary", source = "hex", outer_checksum = "51C0FEF4D72CE7CA507BD188B21C1F00695B3D5B09D7DFE38240BFD3A8E1E9B3" }, ··· 25 24 ] 26 25 27 26 [requirements] 27 + envoy = { version = ">= 1.1.0 and < 2.0.0" } 28 28 gleam_javascript = { version = ">= 1.0.0 and < 2.0.0" } 29 29 gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 30 30 gleam_time = { version = ">= 1.6.0 and < 2.0.0" } 31 31 jot = { version = ">= 8.0.0 and < 9.0.0" } 32 32 lustre = { version = ">= 5.4.0 and < 6.0.0" } 33 33 lustre_ssg = { git = "https://github.com/fruno-bulax/lustre_ssg", ref = "6c132bd34ab75a1144d31c0f896cab0e3cbf80fc" } 34 - shellout = { version = ">= 1.7.0 and < 2.0.0" } 35 34 simplifile = { version = ">= 2.3.2 and < 3.0.0" } 36 35 tom = { version = ">= 2.0.0 and < 3.0.0" }
+28
src/context.gleam
··· 1 + import envoy 2 + import gleam/javascript/promise.{type Promise} 3 + import gleam/result 4 + import highlight.{type Highlighter} 5 + 6 + const env_commit_hash = "TANGLED_COMMIT_SHA" 7 + 8 + const env_gleam_version = "GLEAM_VERSION" 9 + 10 + pub type Context { 11 + SiteMeta(commit_hash: String, gleam_version: String, highlighter: Highlighter) 12 + } 13 + 14 + pub fn fetch() -> Promise(Context) { 15 + use highlighter <- promise.map(highlight.highlighter(highlight_languages)) 16 + let commit_hash = env_commit_hash |> envoy.get |> result.unwrap("hash") 17 + let gleam_version = env_gleam_version |> envoy.get |> result.unwrap("161.789") 18 + SiteMeta(commit_hash:, gleam_version:, highlighter:) 19 + } 20 + 21 + // We could compute these from the pages, but I don't think it's worth it... 22 + const highlight_languages = [ 23 + "gleam", 24 + "javascript", 25 + "css", 26 + "html", 27 + "toml", 28 + ]
-38
src/meta.gleam
··· 1 - import gleam/javascript/promise.{type Promise} 2 - import gleam/result 3 - import highlight.{type Highlighter} 4 - import shellout 5 - 6 - pub type SiteMeta { 7 - SiteMeta(commit_hash: String, gleam_version: String, highlighter: Highlighter) 8 - } 9 - 10 - pub fn fetch() -> Promise(Result(SiteMeta, String)) { 11 - use highlighter <- promise.map(highlight.highlighter(highlight_languages)) 12 - use commit_hash <- result.try(commit_hash()) 13 - use gleam_version <- result.map(gleam_version()) 14 - SiteMeta(commit_hash:, gleam_version:, highlighter:) 15 - } 16 - 17 - fn commit_hash() -> Result(String, String) { 18 - shellout.command(run: "git", with: ["rev-parse", "HEAD"], in: ".", opt: []) 19 - |> result.map_error(fn(error) { "Failed to fetch commit hash: " <> error.1 }) 20 - } 21 - 22 - fn gleam_version() -> Result(String, String) { 23 - let result = shellout.command("gleam", ["--version"], ".", []) 24 - case result { 25 - Ok("gleam " <> version) -> Ok(version) 26 - Ok(_) -> Error("gleam --version returned unexpected result") 27 - Error(error) -> Error("Failed to fetch gleam version: " <> error.1) 28 - } 29 - } 30 - 31 - // We could compute these from the pages, but I don't think it's worth it... 32 - const highlight_languages = [ 33 - "gleam", 34 - "javascript", 35 - "css", 36 - "html", 37 - "toml", 38 - ]
+19 -18
src/page.gleam
··· 1 1 import blog 2 2 import component 3 + import context.{type Context} 3 4 import gleam/dict 4 5 import gleam/list 5 6 import gleam/option.{None, Some} ··· 10 11 import lustre/element.{type Element} 11 12 import lustre/element/html 12 13 import lustre/ssg/djot 13 - import meta.{type SiteMeta} 14 14 import simplifile 15 15 16 16 pub type Page { ··· 40 40 } 41 41 42 42 pub type SiteInfo { 43 - SiteInfo(posts: List(blog.Post), meta: SiteMeta) 43 + SiteInfo(posts: List(blog.Post), meta: Context) 44 44 } 45 45 46 46 pub fn render(page: Page, info: SiteInfo) -> Element(msg) { ··· 94 94 } 95 95 } 96 96 97 - fn navbar(page: Page, meta: SiteMeta) -> Element(msg) { 97 + fn navbar(page: Page, meta: Context) -> Element(msg) { 98 98 html.nav([attribute.id("navbar")], [ 99 99 prompt_left(), 100 100 nav(page), ··· 121 121 html.span([], [html.text("/")]), 122 122 html.span([attribute.class("cursor")], []), 123 123 html.ul([], [ 124 - nav_link(Index, page), 125 - nav_link(Blog, page), 126 - nav_link(Dots, page), 124 + nav_link(page, Index), 125 + nav_link(page, Blog), 126 + nav_link(page, Dots), 127 127 ]), 128 128 ]) 129 129 } 130 130 131 - fn nav_link(to: Page, active: Page) { 132 - let is_active = case to, active { 133 - BlogPost(_), BlogPost(_) | BlogPost(_), Blog -> True 134 - _, _ if to == active -> True 131 + fn nav_link(active: Page, link: Page) { 132 + let is_active = case active, link { 133 + BlogPost(_), Blog -> True 134 + _, _ if link == active -> True 135 135 _, _ -> False 136 136 } 137 + 137 138 html.li([], [ 138 139 html.a( 139 140 [ 140 - attribute.href(route(to)), 141 + attribute.href(route(link)), 141 142 attribute.classes([#("active", is_active)]), 142 143 ], 143 - [html.span([], [html.text(title(to))])], 144 + [html.span([], [html.text(title(link))])], 144 145 ), 145 146 ]) 146 147 } 147 148 148 - fn prompt_right(meta: SiteMeta) -> Element(msg) { 149 + fn prompt_right(context: Context) -> Element(msg) { 149 150 html.div([attribute.id("prompt-right")], [ 150 151 html.div([attribute.class("prompt-pointed-right")], [html.div([], [])]), 151 152 html.div([attribute.id("prompt-commit")], [ ··· 153 154 [ 154 155 attribute.href( 155 156 "https://tangled.org/fruno.win/webbed-site/commit/" 156 - <> meta.commit_hash, 157 + <> context.commit_hash, 157 158 ), 158 159 ], 159 - [html.text(string.slice(meta.commit_hash, 0, 4))], 160 + [html.text(string.slice(context.commit_hash, 0, 4))], 160 161 ), 161 162 ]), 162 163 html.div([attribute.class("prompt-pointed-right")], [html.div([], [])]), ··· 166 167 attribute.alt("Lucy, the mascot of the gleam programming language"), 167 168 attribute.src("/img/gleam.svg"), 168 169 ]), 169 - html.text(meta.gleam_version), 170 + html.text(context.gleam_version), 170 171 ]), 171 172 html.div([attribute.class("prompt-pointed-right")], [html.div([], [])]), 172 173 ]) 173 174 } 174 175 175 - pub fn renderer(meta: SiteMeta) -> djot.Renderer(Element(msg)) { 176 + pub fn renderer(context: Context) -> djot.Renderer(Element(msg)) { 176 177 let to_attributes = fn(attrs) { 177 178 use attrs, key, val <- dict.fold(attrs, []) 178 179 [attribute(key, val), ..attrs] ··· 181 182 djot.Renderer( 182 183 codeblock: fn(attrs, lang, code) { 183 184 let lang = option.unwrap(lang, "text") 184 - let html = highlight.to_html(code, lang, meta.highlighter) 185 + let html = highlight.to_html(code, lang, context.highlighter) 185 186 element.unsafe_raw_html( 186 187 "", 187 188 "div",
+3 -4
src/webbed_site.gleam
··· 1 1 import blog 2 + import context 2 3 import gleam/dict 3 4 import gleam/javascript/promise 4 5 import gleam/list 5 6 import lustre/ssg 6 - import meta 7 7 import page 8 8 9 9 pub fn main() { 10 - use meta <- promise.map(meta.fetch()) 11 - let assert Ok(meta) = meta as "Failed to fetch site meta" 10 + use context <- promise.map(context.fetch()) 12 11 let posts = blog.posts() 13 - let info = page.SiteInfo(posts:, meta:) 12 + let info = page.SiteInfo(posts:, meta: context) 14 13 15 14 let site = 16 15 ssg.new("./dist")