commit 9f2f494f3ce3c8cf55f99d4dd8197bcf92eba263 Author: Hoang Nguyen Date: Tue Jul 11 00:00:00 2023 +0700 Init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..26d8d1b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[{Makefile,*.go}] +indent_style = tab diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..46080a3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.ico filter=lfs diff=lfs merge=lfs -text +*.woff filter=lfs diff=lfs merge=lfs -text +*.woff2 filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2e7327 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/out diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..bf217e8 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,38 @@ +--- +default: + interruptible: true + tags: + - docker + - linux + +workflow: + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + +stages: + - build + - deploy + +build:generate_html: + stage: build + artifacts: + expire_in: 1 hour + paths: + - out/ + image: golang:1.20-alpine + script: + - apk --no-cache add minify make + - make + +deploy:cloudflare_pages: + stage: deploy + image: + name: node:20-alpine + entrypoint: [''] + script: | + npx wrangler pages deploy \ + --project-name=folliehiyuki-cdn \ + --branch="$CI_COMMIT_REF_NAME" \ + out/ + dependencies: + - build:generate_html diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..809dc28 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright © 2023 Hoang Nguyen + +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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a50bc73 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.DEFAULT_GOAL := bundle + +OUTPUT_DIR ?= out + +.PHONY: clean +clean: + @rm -rf $(OUTPUT_DIR) + +.PHONY: gen +gen: + @mkdir -p $(OUTPUT_DIR) + @cp -rf src/* $(OUTPUT_DIR) + @OUTPUT_DIR=$(OUTPUT_DIR) \ + find ./$(OUTPUT_DIR) -mindepth 1 -type d -print -exec go run ./tools/update_html.go {} \; + +.PHONY: minify +minify: + @minify -r ./$(OUTPUT_DIR) -o . + +.PHONY: bundle +bundle: clean gen minify diff --git a/README.md b/README.md new file mode 100644 index 0000000..1cd3f25 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# FollieHiyuki's CDN + +This is a small website, acting like a centralized source for all of my web assets. Most of them are vendored fonts and small CSS files. + +The website is deployed to Cloudflare Pages and is available at . + +## FAQ + +> Why not ``? + +I like being in control of my own stuff. Also, it's because my websites have a strict `Content-Security-Policy` header value (see [_headers](./src/_headers) file for an example). + +> Why not using Chrome or Nginx directory listing? + +I like some theming and little directory/file icons. Also, CloudFlare Pages (where I deploy this project to) isn't a VM hosting platform but a [FaaS](https://en.wikipedia.org/wiki/Function_as_a_Service) provider. + +> Why not using `tree(1)`? + +```bash +$ find ./out/ -mindepth 1 -type d -print -exec sh -c 'tree "$0" \ + -a \ + -i \ + -F \ + -H "." \ + -I "index.html" \ + -T "$0" \ + -L 1 \ + -o "$0/index.html" \ + --noreport \ + --dirsfirst \ + --charset utf-8 \ + --ignore-case' {} \; +``` + +Meh? + +Also, `tree` injects its metadata, CSS and copyright notice into the `index.html` file. Yes, I can yank them out with something like [htmlq](https://github.com/mgdm/htmlq), but I also want to insert my own styling and stuff. + +> Why not using [minify](https://github.com/tdewolff/minify)'s library but its CLI? + +Using the CLI is much easier. And, I don't want a dedicated Go module for this small project with external dependencies. + +## License + +All the vendored files use to their original licenses. Other are licensed under MIT. diff --git a/src/_headers b/src/_headers new file mode 100644 index 0000000..77130df --- /dev/null +++ b/src/_headers @@ -0,0 +1,7 @@ +/* + X-Frame-Options: DENY + X-Content-Type-Options: nosniff + X-DNS-Prefetch-Control: off + Referrer-Policy: no-referrer + Permissions-Policy: interest-cohort=(), geolocation=(), camera=(), microphone=(), display-capture=(), web-share=() + Content-Security-Policy: default-src 'self'; script-src 'none'; frame-ancestors 'none'; child-src 'none'; base-uri 'self' diff --git a/src/css/normalize.css b/src/css/normalize.css new file mode 100644 index 0000000..192eb9c --- /dev/null +++ b/src/css/normalize.css @@ -0,0 +1,349 @@ +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ + +/** + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. + */ + +html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/* Sections + ========================================================================== */ + +/** + * Remove the margin in all browsers. + */ + +body { + margin: 0; +} + +/** + * Render the `main` element consistently in IE. + */ + +main { + display: block; +} + +/** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/* Grouping content + ========================================================================== */ + +/** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Remove the gray background on active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ +} + +/** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + +b, +strong { + font-weight: bolder; +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** + * Add the correct font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove the border on images inside links in IE 10. + */ + +img { + border-style: none; +} + +/* Forms + ========================================================================== */ + +/** + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. + */ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + +button, +input { /* 1 */ + overflow: visible; +} + +/** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + +button, +select { /* 1 */ + text-transform: none; +} + +/** + * Correct the inability to style clickable types in iOS and Safari. + */ + +button, +[type="button"], +[type="reset"], +[type="submit"] { + -webkit-appearance: button; +} + +/** + * Remove the inner border and padding in Firefox. + */ + +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** + * Restore the focus styles unset by the previous rule. + */ + +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** + * Correct the padding in Firefox. + */ + +fieldset { + padding: 0.35em 0.75em 0.625em; +} + +/** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ +} + +/** + * Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + +progress { + vertical-align: baseline; +} + +/** + * Remove the default vertical scrollbar in IE 10+. + */ + +textarea { + overflow: auto; +} + +/** + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. + */ + +[type="checkbox"], +[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + +[type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** + * Remove the inner padding in Chrome and Safari on macOS. + */ + +[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* Interactive + ========================================================================== */ + +/* + * Add the correct display in Edge, IE 10+, and Firefox. + */ + +details { + display: block; +} + +/* + * Add the correct display in all browsers. + */ + +summary { + display: list-item; +} + +/* Misc + ========================================================================== */ + +/** + * Add the correct display in IE 10+. + */ + +template { + display: none; +} + +/** + * Add the correct display in IE 10. + */ + +[hidden] { + display: none; +} diff --git a/src/css/self.css b/src/css/self.css new file mode 100644 index 0000000..2c71bb2 --- /dev/null +++ b/src/css/self.css @@ -0,0 +1,63 @@ +:root { + --color-bg: #f2f4f8; + --color-fg: #3b4252; + --color-blue: #5e81ac; + --color-cyan: #88c0d0; + + @media (prefers-color-scheme: dark) { + --color-bg: #3b4252; + --color-fg: #eceff4; + --color-blue: #81a1c1; + } +} + +*, +*::before, +*::after { + box-sizing: inherit; +} + +body { + box-sizing: border-box; + font-family: "Iosevka Aile Web", sans-serif; + line-height: 1.5; + min-height: 100vh; + margin: 0; + padding: 0; + color: var(--color-fg); + background: var(--color-bg); +} + +main { + margin: auto; + max-width: 48rem; + padding: 2rem; +} + +a { + color: var(--color-blue); + text-decoration: none; + position: relative; +} + +a:hover { + color: var(--color-cyan); + border-bottom: 0.1rem solid var(--color-cyan); +} + +h1 { + font-size: 1.5rem; +} + +h2 { + font-size: 1.25rem; +} + +p { + text-align: justify; +} + +.fa-solid { + font-family: "Font Awesome 6 Free"; + font-size: 1rem; +} diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 0000000..31a9684 --- /dev/null +++ b/src/favicon.ico @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56e5cc65c554ea30a44b158bf3b2e7095054c98921923b809450a0da55afdcf7 +size 107021 diff --git a/src/fonts/devicon/devicon.css b/src/fonts/devicon/devicon.css new file mode 100644 index 0000000..51ff1dc --- /dev/null +++ b/src/fonts/devicon/devicon.css @@ -0,0 +1,7 @@ +@font-face { + font-family: "devicon"; + font-display: block; + font-weight: 400; + font-style: normal; + src: url("devicon.woff") format("woff"); +} diff --git a/src/fonts/devicon/devicon.woff b/src/fonts/devicon/devicon.woff new file mode 100644 index 0000000..12b7481 --- /dev/null +++ b/src/fonts/devicon/devicon.woff @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be0b81a6766738f5a1e0927783320d9bdab4dfe2f3d611d0d53d7ba027023d8f +size 484680 diff --git a/src/fonts/font-awesome/brands.css b/src/fonts/font-awesome/brands.css new file mode 100644 index 0000000..64bf64e --- /dev/null +++ b/src/fonts/font-awesome/brands.css @@ -0,0 +1,7 @@ +@font-face { + font-family: "Font Awesome 6 Brands"; + font-display: block; + font-weight: 400; + font-style: normal; + src: url("fa-brands-400.woff2") format("woff2"); +} diff --git a/src/fonts/font-awesome/fa-brands-400.woff2 b/src/fonts/font-awesome/fa-brands-400.woff2 new file mode 100644 index 0000000..027396a --- /dev/null +++ b/src/fonts/font-awesome/fa-brands-400.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:748332090c4b8e20f95d0ff59f0be20fa9c889359d3b36d4b886d73376054207 +size 108020 diff --git a/src/fonts/font-awesome/fa-solid-900.woff2 b/src/fonts/font-awesome/fa-solid-900.woff2 new file mode 100644 index 0000000..a389264 --- /dev/null +++ b/src/fonts/font-awesome/fa-solid-900.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7152a6933ee3d690ec2af3d09da9d701723d16aa3410a6d80f28ff8866f3b880 +size 150124 diff --git a/src/fonts/font-awesome/solid.css b/src/fonts/font-awesome/solid.css new file mode 100644 index 0000000..daaed3e --- /dev/null +++ b/src/fonts/font-awesome/solid.css @@ -0,0 +1,7 @@ +@font-face { + font-family: "Font Awesome 6 Free"; + font-display: block; + font-weight: 900; + font-style: normal; + src: url("fa-solid-900.woff2") format("woff2"); +} diff --git a/src/fonts/font-logos/font-logos.css b/src/fonts/font-logos/font-logos.css new file mode 100644 index 0000000..1de288e --- /dev/null +++ b/src/fonts/font-logos/font-logos.css @@ -0,0 +1,7 @@ +@font-face { + font-family: "font-logos"; + font-display: block; + font-weight: 400; + font-style: normal; + src: url("font-logos.woff2") format("woff2"); +} diff --git a/src/fonts/font-logos/font-logos.woff2 b/src/fonts/font-logos/font-logos.woff2 new file mode 100644 index 0000000..cd62aa8 --- /dev/null +++ b/src/fonts/font-logos/font-logos.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:392e492c1152eeb74d050b47b0a0910d322a08c4f7d21c962bfdb0c2a4c3cfec +size 15724 diff --git a/src/fonts/iosevka/iosevka-aile-bold.woff2 b/src/fonts/iosevka/iosevka-aile-bold.woff2 new file mode 100644 index 0000000..fd55529 --- /dev/null +++ b/src/fonts/iosevka/iosevka-aile-bold.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1eee2ca89e26d2b8d6aaa298c6118ac352eacff5697eda8a7b409e1c00a44ada +size 1416896 diff --git a/src/fonts/iosevka/iosevka-aile-bolditalic.woff2 b/src/fonts/iosevka/iosevka-aile-bolditalic.woff2 new file mode 100644 index 0000000..b1fa977 --- /dev/null +++ b/src/fonts/iosevka/iosevka-aile-bolditalic.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d124fda4405cbec51caf78d8051e46167c7506fc34a4a14ad775fc7b44624c9 +size 1531672 diff --git a/src/fonts/iosevka/iosevka-aile-italic.woff2 b/src/fonts/iosevka/iosevka-aile-italic.woff2 new file mode 100644 index 0000000..b6122ea --- /dev/null +++ b/src/fonts/iosevka/iosevka-aile-italic.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:807e53ab86565343092508d7b1d0b4d1dfbec6b33ce3674df290954660677f49 +size 1499020 diff --git a/src/fonts/iosevka/iosevka-aile-regular.woff2 b/src/fonts/iosevka/iosevka-aile-regular.woff2 new file mode 100644 index 0000000..b6da3b8 --- /dev/null +++ b/src/fonts/iosevka/iosevka-aile-regular.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cba7d0fa0bc11595a378d83189642b6188278b74f91fe4cb0301c2b121528ca1 +size 1385020 diff --git a/src/fonts/iosevka/iosevka-aile.css b/src/fonts/iosevka/iosevka-aile.css new file mode 100644 index 0000000..7c7dab9 --- /dev/null +++ b/src/fonts/iosevka/iosevka-aile.css @@ -0,0 +1,35 @@ +@font-face { + font-family: "Iosevka Aile Web"; + font-display: swap; + font-weight: 400; + font-stretch: normal; + font-style: normal; + src: url("iosevka-aile-regular.woff2") format("woff2"); +} + +@font-face { + font-family: "Iosevka Aile Web"; + font-display: swap; + font-weight: 400; + font-stretch: normal; + font-style: italic; + src: url("iosevka-aile-italic.woff2") format("woff2"); +} + +@font-face { + font-family: "Iosevka Aile Web"; + font-display: swap; + font-weight: 700; + font-stretch: normal; + font-style: normal; + src: url("iosevka-aile-bold.woff2") format("woff2"); +} + +@font-face { + font-family: "Iosevka Aile Web"; + font-display: swap; + font-weight: 700; + font-stretch: normal; + font-style: italic; + src: url("iosevka-aile-bolditalic.woff2") format("woff2"); +} diff --git a/src/fonts/iosevka/iosevka-bold.woff2 b/src/fonts/iosevka/iosevka-bold.woff2 new file mode 100644 index 0000000..4a1ff08 --- /dev/null +++ b/src/fonts/iosevka/iosevka-bold.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b8edb1ea048dbd831514cf949195d67e23db0ff65515a33690e967fc0434b24 +size 1162212 diff --git a/src/fonts/iosevka/iosevka-bolditalic.woff2 b/src/fonts/iosevka/iosevka-bolditalic.woff2 new file mode 100644 index 0000000..e3b5b70 --- /dev/null +++ b/src/fonts/iosevka/iosevka-bolditalic.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:329dca67ec5581d3660726a4e623cc146860d53d8163dd825860d6f8b43ac481 +size 1254096 diff --git a/src/fonts/iosevka/iosevka-italic.woff2 b/src/fonts/iosevka/iosevka-italic.woff2 new file mode 100644 index 0000000..e810e83 --- /dev/null +++ b/src/fonts/iosevka/iosevka-italic.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92351d1bf611ae40b3a06b5f6f8f66209d3c1c714ca142f0edc21a71f5dea054 +size 1242460 diff --git a/src/fonts/iosevka/iosevka-regular.woff2 b/src/fonts/iosevka/iosevka-regular.woff2 new file mode 100644 index 0000000..f4ee3bb --- /dev/null +++ b/src/fonts/iosevka/iosevka-regular.woff2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9aa7ff6d16dc8cd183e97925d4adf16131f3baef0a26cfcb03c8761bb75446d +size 1152708 diff --git a/src/fonts/iosevka/iosevka.css b/src/fonts/iosevka/iosevka.css new file mode 100644 index 0000000..ce0f3af --- /dev/null +++ b/src/fonts/iosevka/iosevka.css @@ -0,0 +1,35 @@ +@font-face { + font-family: "Iosevka Web"; + font-display: swap; + font-weight: 400; + font-stretch: normal; + font-style: normal; + src: url("iosevka-regular.woff2") format("woff2"); +} + +@font-face { + font-family: "Iosevka Web"; + font-display: swap; + font-weight: 400; + font-stretch: normal; + font-style: italic; + src: url("iosevka-italic.woff2") format("woff2"); +} + +@font-face { + font-family: "Iosevka Web"; + font-display: swap; + font-weight: 700; + font-stretch: normal; + font-style: normal; + src: url("iosevka-bold.woff2") format("woff2"); +} + +@font-face { + font-family: "Iosevka Web"; + font-display: swap; + font-weight: 700; + font-stretch: normal; + font-style: italic; + src: url("iosevka-bolditalic.woff2") format("woff2"); +} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..3c7dbdc --- /dev/null +++ b/src/index.html @@ -0,0 +1,39 @@ + + + + FollieCDN + + + + + + + + + + + + + + + + + + + +
+

FollieHiyuki's personal web assets

+

+ Hi! Welcome to my "Content Delivery Network" running freeloading on Cloudflare. The files served here are used to power my websites, including + folliehiyuki.com and + docs.folliehiyuki.com. The source code is avaliable to see on + GitLab. +

+

Packages

+

+ fonts - Various 3rd-party fonts I use everywhere
+ css - Some minimal, opinionated CSS settings
+

+
+ + diff --git a/tools/index.html.tmpl b/tools/index.html.tmpl new file mode 100644 index 0000000..c1a8240 --- /dev/null +++ b/tools/index.html.tmpl @@ -0,0 +1,35 @@ + + + + {{ .Path }} | FollieCDN + + + + + + + + + + + + + + + + + + + +
+

{{ .Path }}

+

+ ../
+ {{ range .Entries }} + {{ if .IsDir }}{{ else }} {{ end }} + {{ .Name }}
+ {{ end }} +

+
+ + diff --git a/tools/update_html.go b/tools/update_html.go new file mode 100644 index 0000000..3847eec --- /dev/null +++ b/tools/update_html.go @@ -0,0 +1,85 @@ +package main + +import ( + _ "embed" + "html/template" + "log" + "os" + "path" + "regexp" +) + +// A struct based on fs.DirEntry +type Entry struct { + Name string + IsDir bool +} + +var destPrefix = os.Getenv("OUTPUT_DIR") + +//go:embed index.html.tmpl +var indexTemplate string + +// Return the list of entries inside a specified directory +func getEntries(dirPath string) ([]Entry, error) { + dirEntries, err := os.ReadDir(dirPath) + if err != nil { + return nil, err + } + + entryList := []Entry{} + for _, entry := range dirEntries { + // Of course we want to ignore index.html file in the directory listing + if entry.Name() != "index.html" { + entryName := entry.Name() + if entry.IsDir() { + entryName = entryName + "/" + } + entryList = append(entryList, Entry{Name: entryName, IsDir: entry.IsDir()}) + } + } + + return entryList, nil +} + +// Output an index.html file listing entries to a specified destination +func renderIndexHTML(entries []Entry, dest string) error { + tmpl, err := template.New("index.html").Parse(indexTemplate) + if err != nil { + return err + } + + // Get rid of ./out/ prefix from find(1) result + re := regexp.MustCompile(`^\.\/` + destPrefix + `\/`) + dirPath := re.ReplaceAllString(dest, "") + + data := struct { + Path string + Entries []Entry + }{Path: dirPath, Entries: entries} + + // Open the destination index.html file + destFile, err := os.Create(path.Join(dest, "index.html")) + if err != nil { + return err + } + + return tmpl.Execute(destFile, data) +} + +func main() { + if len(os.Args) != 2 { + log.Fatalln("Requires exactly 1 argument (a directory path to evaluate).") + } + + dirPath := os.Args[1] + entries, err := getEntries(dirPath) + if err != nil { + log.Fatalln(err) + } + + err = renderIndexHTML(entries, dirPath) + if err != nil { + log.Fatalln(err) + } +}