From f9828cfefe705805de898a10289ff2bcc0b9c9f4 Mon Sep 17 00:00:00 2001 From: m1kadev <67912368+m1kadev@users.noreply.github.com> Date: Thu, 18 Dec 2025 21:59:28 +0100 Subject: [PATCH] add pastes folder --- .gitignore | 13 +- LICENSE | 21 + build.exs | 126 ++- pastes/paste.html | 54 ++ pull-hljs.sh | 17 + src/colophon.fxg | 5 + src/colophon.html | 48 ++ src/index.css | 4 + src/{template.html => index.html} | 15 +- src/index.js | 19 +- src/projects.fxg | 2 +- static/highlight.min.js | 1242 ----------------------------- 12 files changed, 283 insertions(+), 1283 deletions(-) create mode 100644 LICENSE create mode 100644 pastes/paste.html create mode 100755 pull-hljs.sh create mode 100644 src/colophon.fxg create mode 100644 src/colophon.html rename src/{template.html => index.html} (65%) delete mode 100644 static/highlight.min.js diff --git a/.gitignore b/.gitignore index ae31546b785ff945a7281e3c859cff26dcfe359a..179e94922d46db2c6d455a80091d4938ea52e344 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,4 @@ -/_build/ -/cover/ -/deps/ -/doc/ -/tmp/ -erl_crash.dump -*.ez -www-*.tar -/.elixir_ls -/_build/ /build +/static/highlight.min.js +/static/rust.min.js +/static/html.min.js diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..92fbc069755047dcf1da1499944017400c16cbae --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 mika + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/build.exs b/build.exs index 72d81c0dac328a1ee7aefe10b5a8ddbe82bb4cd2..bec6346f7a5472ed39aeeb4574f03fe0f9a9d234 100644 --- a/build.exs +++ b/build.exs @@ -7,11 +7,41 @@ Mix.install([ Calendar.put_time_zone_database(Tzdata.TimeZoneDatabase) -defmodule Builders do +defmodule Templates do binfo_template = """ - commit=<%= commit %>lightningcss=<%= lightningcss %>html_minifer_next=<%= html_minifier_next %>uglifyjs=<%= uglifyjs %>build_time=<%= build_time %> + commit=<%= commit %>lightningcss=<%= lightningcss %>html_minifier_next=<%= html_minifier_next %>uglifyjs=<%= uglifyjs %>build_time=<%= build_time %> + """ + + pastelink_template = """ + <%= name %> | <%= date %> """ + EEx.function_from_string( + :def, + :build_info, + binfo_template, + [ + :commit, + :lightningcss, + :html_minifier_next, + :uglifyjs, + :build_time + ] + ) + + EEx.function_from_string( + :def, + :pastelink, + pastelink_template, + [ + :location, + :name, + :date + ] + ) +end + +defmodule Builders do def html(input_path) do output_path = String.replace_prefix(input_path, "src", "build") @@ -50,27 +80,55 @@ defmodule Builders do end def fxg(input_path, template) do + own_template = input_path |> String.replace_suffix("fxg", "html") + + case File.read(own_template) do + {:ok, ctemplate} -> _fxg(input_path, ctemplate) + _ -> _fxg(input_path, template) + end + end + + def paste(input_path, template) do + {:ok, rcode} = File.read(input_path) + + output = "build/" <> input_path <> ".html" + + code = + rcode + |> String.replace("&", "&") + |> String.replace("<", "<") + |> String.replace(">", ">") + + lang = Path.extname(input_path) |> String.slice(1..-1//1) + file = Path.basename(input_path) + {:ok, %File.Stat{mtime: mtime}} = File.stat(input_path, time: :posix) + + result = + template + |> String.replace("$LANG", lang) + |> String.replace("$CODE", code) + |> String.replace("$FILENAME", input_path) + |> String.replace("$FILEMETA", "Created on " <> Integer.to_string(mtime)) + + :ok = File.write(output, result) + end + + defp _fxg(input_path, template) do output_path = String.replace_prefix(input_path, "src", "build") |> String.replace_suffix("fxg", "html") {output, 0} = System.cmd("fxg", [input_path]) - output = String.replace(template, "", output) + output = String.replace(template, "", output) File.write(output_path, output) end +end - EEx.function_from_string( - :def, - :build_info, - binfo_template, - [ - :commit, - :lightningcss, - :html_minifier_next, - :uglifyjs, - :build_time - ] - ) +defmodule FileX do + def created(path) do + {:ok, %File.Stat{mtime: {{y, m, d}, _}}} = File.stat(path, time: :local) + Integer.to_string(d) <> "/" <> Integer.to_string(m) <> "/" <> Integer.to_string(y) + end end {commit, 0} = System.cmd("git", ["rev-parse", "HEAD"]) @@ -92,7 +150,7 @@ end # |> Task.async_stream(fn file -> Builders.html(file) end) # |> Enum.to_list() -{:ok, main_template} = File.read("src/template.html") +{:ok, main_template} = File.read("src/index.html") Path.wildcard("src/**/*.css") |> Task.async_stream(fn file -> Builders.css(file) end) @@ -110,10 +168,44 @@ Path.wildcard("static/**/*") |> Task.async_stream(fn file -> File.cp(file, "build/" <> file) end) |> Enum.to_list() +File.mkdir_p("build/pastes") + +{:ok, paste_template} = File.read("pastes/paste.html") + +pastes = Path.wildcard("pastes/**/*") + +pastes +|> Task.async_stream(fn file -> Builders.paste(file, paste_template) end) +|> Enum.to_list() + +# i cant test this :)) hope it works +paste_data = + Map.new(pastes, fn x -> {x, FileX.created(x)} end) + |> Enum.map(fn {x, y} -> Templates.pastelink(x, x, y) end) + |> Enum.join("
") + +pastes_header = """ +

my pastes

+

random code snippets i found useful or wanted to save :))

+
+""" + +paste_index = + main_template + |> String.replace("", pastes_header <> "

" <> paste_data <> "

") + +File.write("build/pastes/index.html", paste_index) + {:ok, date} = DateTime.now("Europe/Amsterdam") build_time = Calendar.strftime(date, "%H:%M:%S %d/%m/%y") File.write( "build/info.txt", - Builders.build_info(commit, lightningcss, html_minifier_next, uglifyjs, build_time) + Templates.build_info( + commit, + lightningcss |> String.split_at(13) |> elem(1), + html_minifier_next, + uglifyjs |> String.split_at(10) |> elem(1), + build_time + ) ) diff --git a/pastes/paste.html b/pastes/paste.html new file mode 100644 index 0000000000000000000000000000000000000000..34e0a062a74dbbf8aa6fc7004b3ee34e32533e63 --- /dev/null +++ b/pastes/paste.html @@ -0,0 +1,54 @@ + + + + + + + home - m1kadev.nl + + + + + + + + +
+
+

$FILENAME

+ $FILEMETA +

+$CODE
+            
+
+
+
+

Deployed from commit , on

+
+
+ + GitHub logo + +
+
+
+
+ +
+

.nl

+

m1kadev

+ +
+ + + + \ No newline at end of file diff --git a/pull-hljs.sh b/pull-hljs.sh new file mode 100755 index 0000000000000000000000000000000000000000..e7edf8fd2638f87e8310576c31e2bee3860fbad9 --- /dev/null +++ b/pull-hljs.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +cd static + +rm highlight.min.js + +rm rust.min.js +rm html.min.js + +rn arta.min.css + +wget https://raw.githubusercontent.com/highlightjs/cdn-release/refs/heads/main/build/highlight.min.js + +wget https://raw.githubusercontent.com/highlightjs/cdn-release/refs/heads/main/build/languages/rust.min.js +wget https://raw.githubusercontent.com/highlightjs/cdn-release/refs/heads/main/build/languages/html.min.js + +wget https://raw.githubusercontent.com/highlightjs/cdn-release/refs/heads/main/build/styles/arta.min.css \ No newline at end of file diff --git a/src/colophon.fxg b/src/colophon.fxg new file mode 100644 index 0000000000000000000000000000000000000000..cd7f4b5f9c8c003eaa653e65918458b3133fcf6a --- /dev/null +++ b/src/colophon.fxg @@ -0,0 +1,5 @@ += Colophon = + +== About == + +you're looking at a <#https://en.wiktionary.org/wiki/beautiful#English beautiful> site, with <#https://caddyserver.com/ caddy> as its backend. all source pages are written in my own markup language, <#https://github.com/m1kadev/fxg fxg>. site generation is done by a homebrewn <#https://github.com/m1kadev/www.m1kadev.nl/blob/main/build.exs elixir script>. all code (including <#https://github.com/m1kadev/fxg fxg>) is licenced under the MIT licence. \ No newline at end of file diff --git a/src/colophon.html b/src/colophon.html new file mode 100644 index 0000000000000000000000000000000000000000..a314734a6df0f33598a99f153f907d1af5623039 --- /dev/null +++ b/src/colophon.html @@ -0,0 +1,48 @@ + + + + + + + home - m1kadev.nl + + + + + + +
+
+ +
+
+
+

Deployed from commit , on . built with lightningcss , + html-minifier-next , and uglifyjs

+
+
+ + GitHub logo + +
+
+
+
+ +
+

.nl

+

m1kadev

+ +
+ + + + \ No newline at end of file diff --git a/src/index.css b/src/index.css index 06f17d779a285c9993f5c4f5869352eb7564e68b..c2cbf22395e2abf9a84ce28687d006108c027b46 100644 --- a/src/index.css +++ b/src/index.css @@ -98,4 +98,8 @@ nav>a { display: block; text-align: right; position: relative; +} + +nav>a { + padding: .1em; } \ No newline at end of file diff --git a/src/template.html b/src/index.html similarity index 65% rename from src/template.html rename to src/index.html index bd53d7da0c93dfe65c912ded559cf94936c0af0d..b8ce5ba24ecee69ad9e3a55554e3d1340c3fa618 100644 --- a/src/template.html +++ b/src/index.html @@ -6,20 +6,22 @@ home - m1kadev.nl + + + - +
- +