From 263ba0d329e8fdf514f73a719bb24c3281561806 Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Fri, 26 Jul 2024 17:08:59 +0200 Subject: [PATCH] add fork --- .gitignore | 7 + CODE_OF_CONDUCT.md | 24 + LICENSE | 21 + README.md | 50 + assets/js/code.js | 301 +++++ assets/js/custom.js | 1 + assets/js/functions.js | 200 +++ assets/js/index.js | 263 ++++ assets/js/mode.js | 64 + assets/js/search/algolia.js | 2 + assets/js/search/fuse.js | 9 + assets/js/search/index.js | 255 ++++ assets/js/search/variables.js | 37 + assets/js/variables.js | 43 + assets/sass/_base.sass | 277 +++++ assets/sass/_blog.sass | 306 +++++ assets/sass/_chart.sass | 38 + assets/sass/_components.sass | 374 ++++++ assets/sass/_custom.sass | 4 + assets/sass/_fonts.sass | 42 + assets/sass/_mermaid.sass | 7 + assets/sass/_nav.sass | 71 ++ assets/sass/_syntax.sass | 250 ++++ assets/sass/_utils.sass | 105 ++ assets/sass/_variables.sass | 56 + assets/sass/main.sass | 18 + dist/.gitkeep | 0 .../.github/workflows/agolia-update.yaml | 101 ++ exampleSite/.github/workflows/aws-deploy.yaml | 118 ++ exampleSite/LICENSE | 201 +++ exampleSite/README.md | 3 + exampleSite/config/.gitkeep | 0 exampleSite/config/_default/languages.toml | 6 + exampleSite/config/_default/markup.toml | 19 + .../config/_default/menus/menu.en.toml | 25 + exampleSite/config/_default/params.toml | 55 + exampleSite/content/_index.md | 33 + exampleSite/content/blog/_index.md | 3 + .../content/blog/creating-a-new-theme.md | 1097 +++++++++++++++++ exampleSite/content/blog/emoji-support.md | 99 ++ exampleSite/content/blog/goisforlovers.md | 339 +++++ exampleSite/content/blog/hugoisforlovers.md | 86 ++ .../content/blog/migrate-from-jekyll.md | 159 +++ exampleSite/content/docs/_index.md | 18 + exampleSite/content/docs/clarity/_index.md | 8 + exampleSite/content/docs/clarity/blogging.md | 55 + exampleSite/content/docs/clarity/customize.md | 133 ++ exampleSite/content/docs/clarity/features.md | 25 + .../content/docs/clarity/getting-started.md | 67 + exampleSite/content/docs/clarity/images.md | 117 ++ .../docs/clarity/syntax-highlighting.md | 42 + .../content/docs/clarity/theme-overrides.md | 38 + exampleSite/content/docs/compose/_index.md | 8 + exampleSite/content/docs/compose/customize.md | 103 ++ .../content/docs/compose/github-actions.md | 28 + .../docs/compose/graphs-charts-tables.md | 103 ++ .../content/docs/compose/install-theme.md | 77 ++ exampleSite/content/docs/compose/mermaid.md | 668 ++++++++++ .../content/docs/compose/organize-content.md | 34 + exampleSite/content/docs/compose/search.md | 68 + .../docs/compose/shortcodes-example.md | 56 + .../content/docs/compose/shortcodes.md | 244 ++++ .../content/docs/compose/use-tina-cms.md | 56 + exampleSite/content/projects.csv | 12 + exampleSite/content/search.md | 5 + exampleSite/content/themes.csv | 4 + exampleSite/content/tutorials/_index.md | 15 + .../content/tutorials/example/_index.md | 8 + .../content/tutorials/example/mermaid.md | 375 ++++++ exampleSite/dist/.gitkeep | 0 exampleSite/go.mod | 5 + exampleSite/go.sum | 30 + exampleSite/hugo.toml | 13 + exampleSite/netlify.toml | 39 + exampleSite/package.json | 18 + ...s_ae9eb86df8175869edaecf50caadd93b.content | 3 + ...sass_ae9eb86df8175869edaecf50caadd93b.json | 1 + ...s_ae9eb86df8175869edaecf50caadd93b.content | 3 + ...sass_ae9eb86df8175869edaecf50caadd93b.json | 1 + ...s_ca26857cefa9076967ab300682271513.content | 3 + ...sass_ca26857cefa9076967ab300682271513.json | 1 + exampleSite/static/admin/.gitignore | 2 + exampleSite/static/images/GitHubMarkDark.svg | 3 + exampleSite/static/images/GitHubMarkLight.svg | 3 + exampleSite/static/images/artist.jpg | Bin 0 -> 54011 bytes exampleSite/static/images/boy.jpg | Bin 0 -> 187992 bytes .../static/images/clarity/article-toc.png | Bin 0 -> 21261 bytes .../static/images/clarity/image-figure.png | Bin 0 -> 9015 bytes .../static/images/clarity/image-inline.png | Bin 0 -> 12789 bytes .../images/clarity/screenshot-darkmode.png | Bin 0 -> 129635 bytes .../clarity/screenshot-mobile-darkmode.png | Bin 0 -> 49649 bytes .../images/clarity/screenshot-mobile.png | Bin 0 -> 49305 bytes .../static/images/clarity/screenshot.png | Bin 0 -> 124394 bytes .../static/images/clarity/syntax-block.gif | Bin 0 -> 1588159 bytes exampleSite/static/images/clarity/tags.png | Bin 0 -> 10080 bytes .../static/images/clarity/tn-darkmode.png | Bin 0 -> 98695 bytes exampleSite/static/images/clarity/tn.png | Bin 0 -> 100835 bytes exampleSite/static/images/compose-light.svg | 10 + exampleSite/static/images/compose.svg | 10 + exampleSite/static/images/frustrated.jpg | Bin 0 -> 222884 bytes exampleSite/static/images/painting.jpg | Bin 0 -> 192528 bytes exampleSite/static/images/scribble.jpg | Bin 0 -> 23360 bytes exampleSite/static/images/speakers.jpg | Bin 0 -> 76734 bytes exampleSite/static/images/street.jpg | Bin 0 -> 178455 bytes exampleSite/static/images/stuck.jpg | Bin 0 -> 247835 bytes exampleSite/tina/config.js | 144 +++ exampleSite/tina/tina-lock.json | 1 + go.mod | 3 + i18n/de.toml | 32 + i18n/en.toml | 32 + i18n/eo.toml | 32 + i18n/es.toml | 32 + i18n/tr.toml | 32 + images/screenshot.png | Bin 0 -> 236011 bytes images/tn.png | Bin 0 -> 112390 bytes layouts/404.html | 6 + layouts/_default/_markup/render-heading.html | 8 + layouts/_default/baseof.html | 47 + layouts/_default/index.json | 22 + layouts/_default/list.html | 14 + layouts/_default/single.html | 7 + layouts/_default/term.html | 36 + layouts/blog/list.html | 45 + layouts/blog/single.html | 31 + layouts/index.html | 5 + layouts/partials/document.html | 8 + layouts/partials/footer.html | 15 + .../partials/functions/getAlgoliaConfig.html | 4 + layouts/partials/functions/getCodeConfig.html | 15 + layouts/partials/functions/getIconPath.html | 6 + layouts/partials/functions/getScript.html | 2 + .../partials/functions/getSearchConfig.html | 6 + layouts/partials/head/index.html | 44 + layouts/partials/head/liteyoutube.html | 24 + layouts/partials/hooks/head.html | 1 + layouts/partials/hooks/scripts.html | 1 + layouts/partials/mode.html | 4 + layouts/partials/nav.html | 48 + layouts/partials/opengraph.html | 6 + layouts/partials/pager.html | 22 + layouts/partials/scripts/bundle.html | 23 + layouts/partials/scripts/getJsBundle.html | 8 + layouts/partials/scripts/mermaid.html | 25 + layouts/partials/scripts/search.html | 14 + layouts/partials/scripts/translations.html | 14 + layouts/partials/search.html | 20 + layouts/partials/share.html | 7 + layouts/partials/sidebar.html | 30 + layouts/partials/sprite.html | 3 + layouts/partials/sprites.html | 91 ++ layouts/search/single.html | 5 + layouts/shortcodes/block.html | 5 + layouts/shortcodes/button.html | 4 + layouts/shortcodes/chart.html | 125 ++ layouts/shortcodes/column.html | 4 + layouts/shortcodes/gallery.html | 12 + layouts/shortcodes/grid.html | 5 + layouts/shortcodes/icon.html | 6 + layouts/shortcodes/image.html | 4 + layouts/shortcodes/liteyoutube.html | 16 + layouts/shortcodes/mermaid.html | 1 + layouts/shortcodes/partial.html | 2 + layouts/shortcodes/picture.html | 8 + layouts/shortcodes/tab.html | 17 + layouts/shortcodes/tabs.html | 10 + layouts/shortcodes/tip.html | 4 + layouts/shortcodes/youtube.html | 8 + static/css/lite-yt-embed.css | 86 ++ static/favicons/android-chrome-192x192.png | Bin 0 -> 14033 bytes static/favicons/android-chrome-512x512.png | Bin 0 -> 45481 bytes static/favicons/apple-touch-icon.png | Bin 0 -> 12491 bytes static/favicons/favicon-16x16.png | Bin 0 -> 646 bytes static/favicons/favicon-32x32.png | Bin 0 -> 1458 bytes static/favicons/favicon.ico | Bin 0 -> 15406 bytes static/favicons/site.webmanifest | 1 + static/fonts/Metropolis-Black.woff | Bin 0 -> 26596 bytes static/fonts/Metropolis-Black.woff2 | Bin 0 -> 23960 bytes static/fonts/Metropolis-BlackItalic.woff | Bin 0 -> 27732 bytes static/fonts/Metropolis-BlackItalic.woff2 | Bin 0 -> 25252 bytes static/fonts/Metropolis-Bold.woff | Bin 0 -> 29916 bytes static/fonts/Metropolis-Bold.woff2 | Bin 0 -> 26428 bytes static/fonts/Metropolis-BoldItalic.woff | Bin 0 -> 31208 bytes static/fonts/Metropolis-BoldItalic.woff2 | Bin 0 -> 27792 bytes static/fonts/Metropolis-ExtraBold.woff | Bin 0 -> 29780 bytes static/fonts/Metropolis-ExtraBold.woff2 | Bin 0 -> 26372 bytes static/fonts/Metropolis-ExtraBoldItalic.woff | Bin 0 -> 31228 bytes static/fonts/Metropolis-ExtraBoldItalic.woff2 | Bin 0 -> 27500 bytes static/fonts/Metropolis-ExtraLight.woff | Bin 0 -> 29344 bytes static/fonts/Metropolis-ExtraLight.woff2 | Bin 0 -> 26000 bytes static/fonts/Metropolis-ExtraLightItalic.woff | Bin 0 -> 31512 bytes .../fonts/Metropolis-ExtraLightItalic.woff2 | Bin 0 -> 27872 bytes static/fonts/Metropolis-Light.woff | Bin 0 -> 29320 bytes static/fonts/Metropolis-Light.woff2 | Bin 0 -> 25912 bytes static/fonts/Metropolis-LightItalic.woff | Bin 0 -> 31340 bytes static/fonts/Metropolis-LightItalic.woff2 | Bin 0 -> 27692 bytes static/fonts/Metropolis-Medium.woff | Bin 0 -> 29652 bytes static/fonts/Metropolis-Medium.woff2 | Bin 0 -> 26360 bytes static/fonts/Metropolis-MediumItalic.woff | Bin 0 -> 31340 bytes static/fonts/Metropolis-MediumItalic.woff2 | Bin 0 -> 28100 bytes static/fonts/Metropolis-Regular.woff | Bin 0 -> 26876 bytes static/fonts/Metropolis-Regular.woff2 | Bin 0 -> 24152 bytes static/fonts/Metropolis-RegularItalic.woff | Bin 0 -> 28440 bytes static/fonts/Metropolis-RegularItalic.woff2 | Bin 0 -> 25616 bytes static/fonts/Metropolis-SemiBold.woff | Bin 0 -> 29824 bytes static/fonts/Metropolis-SemiBold.woff2 | Bin 0 -> 26564 bytes static/fonts/Metropolis-SemiBoldItalic.woff | Bin 0 -> 31268 bytes static/fonts/Metropolis-SemiBoldItalic.woff2 | Bin 0 -> 27772 bytes static/fonts/Metropolis-Thin.woff | Bin 0 -> 26720 bytes static/fonts/Metropolis-Thin.woff2 | Bin 0 -> 23852 bytes static/fonts/Metropolis-ThinItalic.woff | Bin 0 -> 28444 bytes static/fonts/Metropolis-ThinItalic.woff2 | Bin 0 -> 25380 bytes static/icons/carly.svg | 1 + static/icons/check.svg | 1 + static/icons/copy.svg | 1 + static/icons/expand.svg | 1 + static/icons/info.svg | 1 + static/icons/link.svg | 1 + static/icons/moon.svg | 1 + static/icons/next.svg | 43 + static/icons/order.svg | 1 + static/icons/sun.svg | 1 + static/images/github.svg | 1 + static/images/next.svg | 43 + static/images/search.svg | 43 + static/js/chart.min.js | 7 + static/js/lite-yt-embed.js | 169 +++ static/js/w3.js | 440 +++++++ theme.toml | 13 + 228 files changed, 9742 insertions(+) create mode 100644 .gitignore create mode 100644 CODE_OF_CONDUCT.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 assets/js/code.js create mode 100644 assets/js/custom.js create mode 100644 assets/js/functions.js create mode 100644 assets/js/index.js create mode 100644 assets/js/mode.js create mode 100644 assets/js/search/algolia.js create mode 100644 assets/js/search/fuse.js create mode 100644 assets/js/search/index.js create mode 100644 assets/js/search/variables.js create mode 100644 assets/js/variables.js create mode 100644 assets/sass/_base.sass create mode 100644 assets/sass/_blog.sass create mode 100644 assets/sass/_chart.sass create mode 100644 assets/sass/_components.sass create mode 100644 assets/sass/_custom.sass create mode 100644 assets/sass/_fonts.sass create mode 100644 assets/sass/_mermaid.sass create mode 100644 assets/sass/_nav.sass create mode 100644 assets/sass/_syntax.sass create mode 100644 assets/sass/_utils.sass create mode 100644 assets/sass/_variables.sass create mode 100644 assets/sass/main.sass create mode 100644 dist/.gitkeep create mode 100644 exampleSite/.github/workflows/agolia-update.yaml create mode 100644 exampleSite/.github/workflows/aws-deploy.yaml create mode 100644 exampleSite/LICENSE create mode 100644 exampleSite/README.md create mode 100644 exampleSite/config/.gitkeep create mode 100644 exampleSite/config/_default/languages.toml create mode 100644 exampleSite/config/_default/markup.toml create mode 100644 exampleSite/config/_default/menus/menu.en.toml create mode 100644 exampleSite/config/_default/params.toml create mode 100644 exampleSite/content/_index.md create mode 100644 exampleSite/content/blog/_index.md create mode 100644 exampleSite/content/blog/creating-a-new-theme.md create mode 100644 exampleSite/content/blog/emoji-support.md create mode 100644 exampleSite/content/blog/goisforlovers.md create mode 100644 exampleSite/content/blog/hugoisforlovers.md create mode 100644 exampleSite/content/blog/migrate-from-jekyll.md create mode 100644 exampleSite/content/docs/_index.md create mode 100644 exampleSite/content/docs/clarity/_index.md create mode 100644 exampleSite/content/docs/clarity/blogging.md create mode 100644 exampleSite/content/docs/clarity/customize.md create mode 100644 exampleSite/content/docs/clarity/features.md create mode 100644 exampleSite/content/docs/clarity/getting-started.md create mode 100644 exampleSite/content/docs/clarity/images.md create mode 100644 exampleSite/content/docs/clarity/syntax-highlighting.md create mode 100644 exampleSite/content/docs/clarity/theme-overrides.md create mode 100644 exampleSite/content/docs/compose/_index.md create mode 100644 exampleSite/content/docs/compose/customize.md create mode 100644 exampleSite/content/docs/compose/github-actions.md create mode 100644 exampleSite/content/docs/compose/graphs-charts-tables.md create mode 100755 exampleSite/content/docs/compose/install-theme.md create mode 100644 exampleSite/content/docs/compose/mermaid.md create mode 100644 exampleSite/content/docs/compose/organize-content.md create mode 100644 exampleSite/content/docs/compose/search.md create mode 100644 exampleSite/content/docs/compose/shortcodes-example.md create mode 100644 exampleSite/content/docs/compose/shortcodes.md create mode 100644 exampleSite/content/docs/compose/use-tina-cms.md create mode 100644 exampleSite/content/projects.csv create mode 100644 exampleSite/content/search.md create mode 100644 exampleSite/content/themes.csv create mode 100644 exampleSite/content/tutorials/_index.md create mode 100644 exampleSite/content/tutorials/example/_index.md create mode 100644 exampleSite/content/tutorials/example/mermaid.md create mode 100644 exampleSite/dist/.gitkeep create mode 100644 exampleSite/go.mod create mode 100644 exampleSite/go.sum create mode 100644 exampleSite/hugo.toml create mode 100644 exampleSite/netlify.toml create mode 100644 exampleSite/package.json create mode 100644 exampleSite/resources/_gen/assets/sass/main.sass_ae9eb86df8175869edaecf50caadd93b.content create mode 100644 exampleSite/resources/_gen/assets/sass/main.sass_ae9eb86df8175869edaecf50caadd93b.json create mode 100644 exampleSite/resources/_gen/assets/sass/sass/main.sass_ae9eb86df8175869edaecf50caadd93b.content create mode 100644 exampleSite/resources/_gen/assets/sass/sass/main.sass_ae9eb86df8175869edaecf50caadd93b.json create mode 100644 exampleSite/resources/_gen/assets/sass/sass/main.sass_ca26857cefa9076967ab300682271513.content create mode 100644 exampleSite/resources/_gen/assets/sass/sass/main.sass_ca26857cefa9076967ab300682271513.json create mode 100644 exampleSite/static/admin/.gitignore create mode 100644 exampleSite/static/images/GitHubMarkDark.svg create mode 100644 exampleSite/static/images/GitHubMarkLight.svg create mode 100644 exampleSite/static/images/artist.jpg create mode 100644 exampleSite/static/images/boy.jpg create mode 100644 exampleSite/static/images/clarity/article-toc.png create mode 100644 exampleSite/static/images/clarity/image-figure.png create mode 100644 exampleSite/static/images/clarity/image-inline.png create mode 100644 exampleSite/static/images/clarity/screenshot-darkmode.png create mode 100644 exampleSite/static/images/clarity/screenshot-mobile-darkmode.png create mode 100644 exampleSite/static/images/clarity/screenshot-mobile.png create mode 100644 exampleSite/static/images/clarity/screenshot.png create mode 100644 exampleSite/static/images/clarity/syntax-block.gif create mode 100644 exampleSite/static/images/clarity/tags.png create mode 100644 exampleSite/static/images/clarity/tn-darkmode.png create mode 100644 exampleSite/static/images/clarity/tn.png create mode 100644 exampleSite/static/images/compose-light.svg create mode 100644 exampleSite/static/images/compose.svg create mode 100644 exampleSite/static/images/frustrated.jpg create mode 100644 exampleSite/static/images/painting.jpg create mode 100644 exampleSite/static/images/scribble.jpg create mode 100644 exampleSite/static/images/speakers.jpg create mode 100644 exampleSite/static/images/street.jpg create mode 100644 exampleSite/static/images/stuck.jpg create mode 100644 exampleSite/tina/config.js create mode 100644 exampleSite/tina/tina-lock.json create mode 100644 go.mod create mode 100644 i18n/de.toml create mode 100644 i18n/en.toml create mode 100644 i18n/eo.toml create mode 100644 i18n/es.toml create mode 100644 i18n/tr.toml create mode 100644 images/screenshot.png create mode 100644 images/tn.png create mode 100644 layouts/404.html create mode 100644 layouts/_default/_markup/render-heading.html create mode 100644 layouts/_default/baseof.html create mode 100644 layouts/_default/index.json create mode 100644 layouts/_default/list.html create mode 100644 layouts/_default/single.html create mode 100644 layouts/_default/term.html create mode 100644 layouts/blog/list.html create mode 100644 layouts/blog/single.html create mode 100644 layouts/index.html create mode 100644 layouts/partials/document.html create mode 100644 layouts/partials/footer.html create mode 100644 layouts/partials/functions/getAlgoliaConfig.html create mode 100644 layouts/partials/functions/getCodeConfig.html create mode 100644 layouts/partials/functions/getIconPath.html create mode 100644 layouts/partials/functions/getScript.html create mode 100644 layouts/partials/functions/getSearchConfig.html create mode 100644 layouts/partials/head/index.html create mode 100644 layouts/partials/head/liteyoutube.html create mode 100644 layouts/partials/hooks/head.html create mode 100644 layouts/partials/hooks/scripts.html create mode 100644 layouts/partials/mode.html create mode 100644 layouts/partials/nav.html create mode 100644 layouts/partials/opengraph.html create mode 100644 layouts/partials/pager.html create mode 100644 layouts/partials/scripts/bundle.html create mode 100644 layouts/partials/scripts/getJsBundle.html create mode 100644 layouts/partials/scripts/mermaid.html create mode 100644 layouts/partials/scripts/search.html create mode 100644 layouts/partials/scripts/translations.html create mode 100644 layouts/partials/search.html create mode 100644 layouts/partials/share.html create mode 100644 layouts/partials/sidebar.html create mode 100644 layouts/partials/sprite.html create mode 100644 layouts/partials/sprites.html create mode 100644 layouts/search/single.html create mode 100644 layouts/shortcodes/block.html create mode 100644 layouts/shortcodes/button.html create mode 100644 layouts/shortcodes/chart.html create mode 100644 layouts/shortcodes/column.html create mode 100644 layouts/shortcodes/gallery.html create mode 100644 layouts/shortcodes/grid.html create mode 100644 layouts/shortcodes/icon.html create mode 100644 layouts/shortcodes/image.html create mode 100644 layouts/shortcodes/liteyoutube.html create mode 100644 layouts/shortcodes/mermaid.html create mode 100644 layouts/shortcodes/partial.html create mode 100644 layouts/shortcodes/picture.html create mode 100644 layouts/shortcodes/tab.html create mode 100644 layouts/shortcodes/tabs.html create mode 100644 layouts/shortcodes/tip.html create mode 100644 layouts/shortcodes/youtube.html create mode 100644 static/css/lite-yt-embed.css create mode 100644 static/favicons/android-chrome-192x192.png create mode 100644 static/favicons/android-chrome-512x512.png create mode 100644 static/favicons/apple-touch-icon.png create mode 100644 static/favicons/favicon-16x16.png create mode 100644 static/favicons/favicon-32x32.png create mode 100644 static/favicons/favicon.ico create mode 100644 static/favicons/site.webmanifest create mode 100644 static/fonts/Metropolis-Black.woff create mode 100644 static/fonts/Metropolis-Black.woff2 create mode 100644 static/fonts/Metropolis-BlackItalic.woff create mode 100644 static/fonts/Metropolis-BlackItalic.woff2 create mode 100644 static/fonts/Metropolis-Bold.woff create mode 100644 static/fonts/Metropolis-Bold.woff2 create mode 100644 static/fonts/Metropolis-BoldItalic.woff create mode 100644 static/fonts/Metropolis-BoldItalic.woff2 create mode 100644 static/fonts/Metropolis-ExtraBold.woff create mode 100644 static/fonts/Metropolis-ExtraBold.woff2 create mode 100644 static/fonts/Metropolis-ExtraBoldItalic.woff create mode 100644 static/fonts/Metropolis-ExtraBoldItalic.woff2 create mode 100644 static/fonts/Metropolis-ExtraLight.woff create mode 100644 static/fonts/Metropolis-ExtraLight.woff2 create mode 100644 static/fonts/Metropolis-ExtraLightItalic.woff create mode 100644 static/fonts/Metropolis-ExtraLightItalic.woff2 create mode 100644 static/fonts/Metropolis-Light.woff create mode 100644 static/fonts/Metropolis-Light.woff2 create mode 100644 static/fonts/Metropolis-LightItalic.woff create mode 100644 static/fonts/Metropolis-LightItalic.woff2 create mode 100644 static/fonts/Metropolis-Medium.woff create mode 100644 static/fonts/Metropolis-Medium.woff2 create mode 100644 static/fonts/Metropolis-MediumItalic.woff create mode 100644 static/fonts/Metropolis-MediumItalic.woff2 create mode 100644 static/fonts/Metropolis-Regular.woff create mode 100644 static/fonts/Metropolis-Regular.woff2 create mode 100644 static/fonts/Metropolis-RegularItalic.woff create mode 100644 static/fonts/Metropolis-RegularItalic.woff2 create mode 100644 static/fonts/Metropolis-SemiBold.woff create mode 100644 static/fonts/Metropolis-SemiBold.woff2 create mode 100644 static/fonts/Metropolis-SemiBoldItalic.woff create mode 100644 static/fonts/Metropolis-SemiBoldItalic.woff2 create mode 100644 static/fonts/Metropolis-Thin.woff create mode 100644 static/fonts/Metropolis-Thin.woff2 create mode 100644 static/fonts/Metropolis-ThinItalic.woff create mode 100644 static/fonts/Metropolis-ThinItalic.woff2 create mode 100644 static/icons/carly.svg create mode 100644 static/icons/check.svg create mode 100644 static/icons/copy.svg create mode 100644 static/icons/expand.svg create mode 100644 static/icons/info.svg create mode 100644 static/icons/link.svg create mode 100644 static/icons/moon.svg create mode 100644 static/icons/next.svg create mode 100644 static/icons/order.svg create mode 100644 static/icons/sun.svg create mode 100644 static/images/github.svg create mode 100644 static/images/next.svg create mode 100644 static/images/search.svg create mode 100644 static/js/chart.min.js create mode 100644 static/js/lite-yt-embed.js create mode 100644 static/js/w3.js create mode 100644 theme.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7184ddc --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +public/ +node_modules/ +.DS_Store +package-lock.json +yarn.lock +__generated__ +.hugo_build.lock diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..307feec --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,24 @@ +# Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Will be civil +* Focusing on what is best for the community + +Examples of unacceptable behavior by participants include: + +* Trolling, insulting/derogatory comments, and personal or political attacks +* Publishing others' private information, such as a physical or electronic + address, without explicit permission + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior. They also have the right to proceed as they wish. Usually on a __good-faith__ basis. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at . All +complaints will be neither be reviewed nor investigated. Instigators will simply be ignored or blocked. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8270993 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Weru + +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/README.md b/README.md new file mode 100644 index 0000000..de30075 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Compose + +Compose is a [Hugo](https://gohugo.io/) theme for documentation websites. The theme provides a simple navigation & structure. + +![Hugo Compose Theme](https://raw.githubusercontent.com/onweru/compose/master/images/tn.png) + +## Features + +1. Documentation +2. Gallery Support +3. Native lazy loading of images +4. Live search +5. Flowcharts, Piecharts, doughnut & bar charts support +6. Searchable & Sortable tables +7. Syntax highlighting +8. Mermaid Support + +## Documentation + +- [Install Compose theme](https://composedocs.netlify.app/docs/compose/install-theme/) +- [Use Tina CMS](https://composedocs.netlify.app/docs/compose/use-tina-cms/) +- [Customize your site](https://composedocs.netlify.app/docs/compose/customize/) +- [Configure search](https://composedocs.netlify.app/docs/compose/search/) +- [Shortcodes](https://composedocs.netlify.app/docs/compose/shortcodes/) +- [Mermaid](https://composedocs.netlify.app/docs/compose/mermaid/) + +## ExampleSite + +The [exampleSite](https://github.com/onweru/compose/tree/master/exampleSite) serves as this theme's [user guide](https://composedocs.netlify.app/docs/compose/install-theme/) . + +This guide covers the necessary bits. As the project evolves, the user-guide will get more comprehensive + +You can use Hugo to generate and serve a local copy of the guide (also useful for testing local theme changes). + +``` +git clone --recurse-submodules --depth 1 https://github.com/onweru/compose.git +cd compose/exampleSite/ +hugo server --themesDir ../.. +``` + +### Also built by Weru + +1. [Clarity Theme](https://github.com/chipzoller/hugo-clarity) +2. [Newsroom Theme](https://github.com/onweru/newsroom) +3. [Swift Theme](https://github.com/onweru/hugo-swift-theme) +4. [Browse Theme](https://github.com/onweru/browse) + +## License + +This theme is available under the [MIT license](https://github.com/onweru/compose/blob/master/LICENSE). diff --git a/assets/js/code.js b/assets/js/code.js new file mode 100644 index 0000000..578c311 --- /dev/null +++ b/assets/js/code.js @@ -0,0 +1,301 @@ +const snippet_actions = [ + { + icon: 'copy', + id: 'copy', + title: copy_text, + show: true + }, + { + icon: 'order', + id: 'lines', + title: toggle_line_numbers_text, + show: true + }, + { + icon: 'carly', + id: 'wrap', + title: toggle_line_wrap_text, + show: false + }, + { + icon: 'expand', + id: 'expand', + title: resize_snippet, + show: false + } +]; + +function addLines(block) { + let text = block.textContent; + const snippet_fragment = []; + if (text.includes('\n') && block.closest('pre') && !block.children.length) { + text = text.split('\n'); + text.forEach((text_node, index) => { + if(text_node.trim().length) { + const new_node = ` + + ${index + 1} + ${text_node.trim()} + `.trim(); + // snippet_fragment.push(':;:'); + snippet_fragment.push(new_node); + block.closest('pre').className = 'chroma'; + pushClass(block, 'language-unknown'); + block.dataset.lang = not_set; + } + }); + + block.innerHTML = snippet_fragment.join('').trim(' '); + } +} + +function wrapOrphanedPreElements() { + const pres = elems('pre'); + Array.from(pres).forEach(function(pre){ + const parent = pre.parentNode; + const is_orpaned = !containsClass(parent, highlight); + if(is_orpaned) { + const pre_wrapper = createEl(); + pre_wrapper.className = highlight; + const outer_wrapper = createEl(); + outer_wrapper.className = highlight_wrap; + wrapEl(pre, pre_wrapper); + wrapEl(pre_wrapper, outer_wrapper); + } + }) + /* + @Todo + 1. Add UI control to orphaned blocks + */ +} + +wrapOrphanedPreElements(); + +function codeBlocks() { + const marked_code_blocks = elems('code'); + const blocks = Array.from(marked_code_blocks).filter(function(block){ + addLines(block); + return block.closest("pre") && !Array.from(block.classList).includes('noClass'); + }).map(function(block){ + return block + }); + return blocks; +} + +function codeBlockFits(block) { + // return false if codeblock overflows + const block_width = block.offsetWidth; + const highlight_block_width = block.closest(`.${highlight}`).offsetWidth; + return block_width <= highlight_block_width ? true : false; +} + +function maxHeightIsSet(elem) { + let max_height = elem.style.maxHeight; + return max_height.includes('px') +} + +function restrainCodeBlockHeight(lines) { + const last_line = lines[max_lines-1]; + let max_code_block_height = full_height; + if(last_line) { + const last_line_pos = last_line.offsetTop; + if(last_line_pos !== 0) { + max_code_block_height = `${last_line_pos}px`; + const codeBlock = lines[0].parentNode; + const outer_block = codeBlock.closest(`.${highlight}`); + const is_expanded = containsClass(outer_block, panel_expanded); + if(!is_expanded) { + codeBlock.dataset.height = max_code_block_height; + codeBlock.style.maxHeight = max_code_block_height; + } + } + } +} + +const blocks = codeBlocks(); + +function collapseCodeBlock(block) { + const lines = elems(line_class, block); + const code_lines = lines.length; + if (code_lines > max_lines) { + const expand_dot = createEl() + pushClass(expand_dot, panel_expand); + pushClass(expand_dot, panel_from); + expand_dot.title = "Toggle snippet"; + expand_dot.textContent = "..."; + const outer_block = block.closest('.highlight'); + window.setTimeout(function(){ + const expand_icon = outer_block.nextElementSibling.lastElementChild; + deleteClass(expand_icon, panel_hide); + }, 150) + + restrainCodeBlockHeight(lines); + const highlight_element = block.parentNode.parentNode; + highlight_element.appendChild(expand_dot); + } +} + +blocks.forEach(function(block){ + collapseCodeBlock(block); +}) + +function actionPanel() { + const panel = createEl(); + panel.className = panel_box; + + snippet_actions.forEach(function(button) { + // create button + const btn = createEl('a'); + btn.href = '#'; + btn.title = button.title; + btn.className = `icon panel_icon panel_${button.id}`; + button.show ? false : pushClass(btn, panel_hide); + // load icon inside button + loadSvg(button.icon, btn); + // append button on panel + panel.appendChild(btn); + }); + + return panel; +} + +function toggleLineNumbers(elems) { + if(elems) { + // mark the code element when there are no lines + elems.forEach(elem => modifyClass(elem, 'pre_nolines')); + restrainCodeBlockHeight(elems); + } +} + +function toggleLineWrap(elem) { + modifyClass(elem, 'pre_wrap'); + // retain max number of code lines on line wrap + const lines = elems('.ln', elem); + restrainCodeBlockHeight(lines); +} + +function copyCode(code_element) { + + const copy_btn = code_element.parentNode.parentNode.querySelector(`.${copy_id}`); + const original_title = copy_btn.title; + loadSvg('check', copy_btn); + copy_btn.title = copied_text; + + // remove line numbers before copying + code_element = code_element.cloneNode(true); + const line_numbers = elems('.ln', code_element); + line_numbers.length ? line_numbers.forEach(line => line.remove()) : false; + + // remove leading '$' from all shell snippets + let lines = elems('span', code_element); + lines.forEach(line => { + const text = line.textContent.trim(' '); + if(text.indexOf('$') === 0) { + line.textContent = line.textContent.replace('$ ', ''); + } + }) + const snippet = code_element.textContent.trim(' '); + // copy code + copyToClipboard(snippet); + + setTimeout(function() { + copy_btn.title = original_title; + loadSvg('copy', copy_btn); + }, 2250); +} + +(function codeActions(){ + const highlight_wrap_id = highlight_wrap; + blocks.forEach(function(block){ + // disable line numbers if disabled globally + show_lines === false ? toggleLineNumbers(elems('.ln', block)) : false; + + const highlight_element = block.parentNode.parentNode; + // wrap code block in a div + const highlight_wrapper = createEl(); + highlight_wrapper.className = highlight_wrap_id; + + wrapEl(highlight_element, highlight_wrapper); + + const panel = actionPanel(); + // show wrap icon only if the code block needs wrapping + const wrap_icon = elem(`.${wrap_id}`, panel); + codeBlockFits(block) ? false : deleteClass(wrap_icon, panel_hide); + + // append buttons + highlight_wrapper.appendChild(panel); + }); + + function isItem(target, id) { + // if is item or within item + return target.matches(`.${id}`) || target.closest(`.${id}`); + } + + function showActive(target, targetClass) { + const target_element = target.matches(`.${targetClass}`) ? target : target.closest(`.${targetClass}`); + + deleteClass(target_element, active); + setTimeout(function() { + modifyClass(target_element, active) + }, 50) + } + + doc.addEventListener('click', function(event){ + // copy code block + const target = event.target; + const is_copy_icon = isItem(target, copy_id); + const is_wrap_icon = isItem(target, wrap_id); + const is_lines_icon = isItem(target, lines_id); + const is_expand_icon = isItem(target, panel_expand); + const is_actionable = is_copy_icon || is_wrap_icon || is_lines_icon || is_expand_icon; + + if(is_actionable) { + event.preventDefault(); + showActive(target, 'icon'); + const code_element = target.closest(`.${highlight_wrap_id}`).firstElementChild.firstElementChild; + let lineNumbers = elems('.ln', code_element); + + is_wrap_icon ? toggleLineWrap(code_element) : false; + is_lines_icon ? toggleLineNumbers(lineNumbers) : false; + + if (is_expand_icon) { + let this_code_block = code_element.firstElementChild; + const outer_block = this_code_block.closest('.highlight'); + if(maxHeightIsSet(this_code_block)) { + this_code_block.style.maxHeight = full_height; + // mark code block as expanded + pushClass(outer_block, panel_expanded) + } else { + this_code_block.style.maxHeight = this_code_block.dataset.height; + // unmark code block as expanded + deleteClass(outer_block, panel_expanded) + } + } + + is_copy_icon ? copyCode(code_element) : false; + } + }); + + (function addLangLabel() { + blocks.forEach(block => { + let label = block.dataset.lang; + const is_shell_based = shell_based.includes(label); + if(is_shell_based) { + const lines = elems(line_class, block); + Array.from(lines).forEach(line => { + line = line.lastElementChild; + let line_contents = line.textContent.trim(' '); + line_contents.indexOf('$') !== 0 && line_contents.trim(' ').length ? pushClass(line, 'shell') : false; + }); + } + + label = label === 'sh' ? 'shell' : label; + if(label !== "fallback") { + const label_el = createEl(); + label_el.textContent = label; + pushClass(label_el, 'lang'); + block.closest(`.${highlight_wrap}`).appendChild(label_el); + } + }); + })(); +})(); diff --git a/assets/js/custom.js b/assets/js/custom.js new file mode 100644 index 0000000..11b1d82 --- /dev/null +++ b/assets/js/custom.js @@ -0,0 +1 @@ +// add custom js in this file \ No newline at end of file diff --git a/assets/js/functions.js b/assets/js/functions.js new file mode 100644 index 0000000..10f3f8f --- /dev/null +++ b/assets/js/functions.js @@ -0,0 +1,200 @@ +function isObj(obj) { + return (obj && typeof obj === 'object' && obj !== null) ? true : false; +} + +function createEl(element = 'div') { + return document.createElement(element); +} + +function emptyEl(el) { + while(el.firstChild) + el.removeChild(el.firstChild); +} + +function elem(selector, parent = document){ + let elem = isObj(parent) ? parent.querySelector(selector) : false; + return elem ? elem : false; +} + +function elems(selector, parent = document) { + return isObj(parent) ? parent.querySelectorAll(selector) : []; +} + +function pushClass(el, targetClass) { + if (isObj(el) && targetClass) { + let elClass = el.classList; + elClass.contains(targetClass) ? false : elClass.add(targetClass); + } +} + +function deleteClass(el, targetClass) { + if (isObj(el) && targetClass) { + let elClass = el.classList; + elClass.contains(targetClass) ? elClass.remove(targetClass) : false; + } +} + +function modifyClass(el, targetClass) { + if (isObj(el) && targetClass) { + const elClass = el.classList; + elClass.contains(targetClass) ? elClass.remove(targetClass) : elClass.add(targetClass); + } +} + +function containsClass(el, targetClass) { + if (isObj(el) && targetClass && el !== document ) { + return el.classList.contains(targetClass) ? true : false; + } +} + +function isChild(node, parentClass) { + let objectsAreValid = isObj(node) && parentClass && typeof parentClass == 'string'; + return (objectsAreValid && node.closest(parentClass)) ? true : false; +} + +function elemAttribute(elem, attr, value = null) { + if (value) { + elem.setAttribute(attr, value); + } else { + value = elem.getAttribute(attr); + return value ? value : false; + } +} + +function deleteChars(str, subs) { + let newStr = str; + if (Array.isArray(subs)) { + for (let i = 0; i < subs.length; i++) { + newStr = newStr.replace(subs[i], ''); + } + } else { + newStr = newStr.replace(subs, ''); + } + return newStr; +} + +function isBlank(str) { + return (!str || str.trim().length === 0); +} + +function isMatch(element, selectors) { + if(isObj(element)) { + if(selectors.isArray) { + let matching = selectors.map(function(selector){ + return element.matches(selector) + }) + return matching.includes(true); + } + return element.matches(selectors) + } +} + +function closestInt(goal, collection) { + return collection.reduce(function (prev, curr) { + return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev); + }); +} + +function hasClasses(el) { + if(isObj(el)) { + const classes = el.classList; + return classes.length + } +} + +function wrapEl(el, wrapper) { + el.parentNode.insertBefore(wrapper, el); + wrapper.appendChild(el); +} + +function wrapText(text, context, wrapper = 'mark') { + let open = `<${wrapper}>`; + let close = ``; + let escapedOpen = `%3C${wrapper}%3E`; + let escapedClose = `%3C/${wrapper}%3E`; + function wrap(context) { + let c = context.innerHTML; + let pattern = new RegExp(text, "gi"); + let matches = text.length ? c.match(pattern) : null; + + if(matches) { + matches.forEach(function(matchStr){ + c = c.replaceAll(matchStr, `${open}${matchStr}${close}`); + context.innerHTML = c; + }); + + const images = elems('img', context); + + if(images) { + images.forEach(image => { + image.src = image.src.replaceAll(open, '').replaceAll(close, '').replaceAll(escapedOpen, '').replaceAll(escapedClose, ''); + }); + } + } + } + + const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "td"]; + + contents.forEach(function(c){ + const cs = elems(c, context); + if(cs.length) { + cs.forEach(function(cx, index){ + if(cx.children.length >= 1) { + Array.from(cx.children).forEach(function(child){ + wrap(child); + }) + wrap(cx); + } else { + wrap(cx); + } + // sanitize urls and ids + }); + } + }); + + const hyperLinks = elems('a'); + if(hyperLinks) { + hyperLinks.forEach(function(link){ + link.href = link.href.replaceAll(encodeURI(open), "").replaceAll(encodeURI(close), ""); + }); + } +} + +function parseBoolean(string = "") { + string = string.trim().toLowerCase(); + switch (string) { + case 'true': + return true; + case 'false': + return false; + default: + return undefined; + } +} + +function loadSvg(icon, parent) { + parent.innerHTML = ` + + + `; +} + +function copyToClipboard(str) { + let copy, selection, selected; + copy = createEl('textarea'); + copy.value = str; + copy.setAttribute('readonly', ''); + copy.style.position = 'absolute'; + copy.style.left = '-9999px'; + selection = document.getSelection(); + doc.appendChild(copy); + // check if there is any selected content + selected = selection.rangeCount > 0 ? selection.getRangeAt(0) : false; + copy.select(); + document.execCommand('copy'); + doc.removeChild(copy); + if (selected) { // if a selection existed before copying + selection.removeAllRanges(); // unselect existing selection + selection.addRange(selected); // restore the original selection + } +} \ No newline at end of file diff --git a/assets/js/index.js b/assets/js/index.js new file mode 100644 index 0000000..8923fc4 --- /dev/null +++ b/assets/js/index.js @@ -0,0 +1,263 @@ +(function calcNavHeight(){ + return (elem('.nav_header').offsetHeight + 25); +})(); + +function toggleMenu(event) { + const target = event.target; + const is_toggle_control = target.matches(`.${toggle_id}`); + const is_with_toggle_control = target.closest(`.${toggle_id}`); + const show_instances = elems(`.${show_id}`) ? Array.from(elems(`.${show_id}`)) : []; + const menu_instance = target.closest(`.${menu}`); + + function showOff(target, self = false) { + show_instances.forEach(function(show_instance){ + !self ? deleteClass(show_instance, show_id) : false; + show_instance !== target.closest(`.${menu}`) ? deleteClass(show_instance, show_id) : false; + }); + } + + if(is_toggle_control || is_with_toggle_control) { + const menu = is_with_toggle_control ? is_with_toggle_control.parentNode.parentNode : target.parentNode.parentNode; + event.preventDefault(); + modifyClass(menu, show_id); + } else { + !menu_instance ? showOff(target) : showOff(target, true); + } +} + +(function markInlineCodeTags(){ + const code_blocks = elems('code'); + if(code_blocks) { + code_blocks.forEach(function(code_block){ + if(!hasClasses(code_block)) { + code_block.children.length ? false : pushClass(code_block, 'noClass'); + } + }); + } +})(); + +function featureHeading(){ + // show active heading at top. + const link_class = "section_link"; + const title_class = "section_title"; + const parent = elem(".aside"); + if(parent) { + let active_heading = elem(`.${link_class}.${active}`); + active_heading = active_heading ? active_heading : elem(`.${title_class}.${active}`); + parent.scroll({ + top: active_heading.offsetTop, + left: 0, + // behavior: 'smooth' + }); + } +} + +function activeHeading(position, list_links) { + let links_to_modify = Object.create(null); + links_to_modify.active = list_links.filter(function(link) { + return containsClass(link, active); + })[0]; + + // activeTocLink ? deleteClass + + links_to_modify.new = list_links.filter(function(link){ + return parseInt(link.dataset.position) === position + })[0]; + + if (links_to_modify.active != links_to_modify.new) { + links_to_modify.active ? deleteClass(links_to_modify.active, active): false; + pushClass(links_to_modify.new, active); + } +}; + +setTimeout(() => { + featureHeading(); +}, 50); + +function updateDate() { + const date = new Date(); + const year = date.getFullYear().toString; + const year_el = elem('.year'); + year_el ? year.textContent = year : false; +} + +function customizeSidebar() { + const tocActive = 'toc_active'; + const aside = elem('aside'); + const tocs = elems('nav', aside); + if(tocs) { + tocs.forEach(function(toc){ + toc.id = ""; + pushClass(toc, 'toc'); + if(toc.children.length >= 1) { + const toc_items = Array.from(toc.children[0].children); + + const previous_heading = toc.previousElementSibling; + previous_heading.matches(`.${active}`) ? pushClass(toc, tocActive) : false; + + toc_items.forEach(function(item){ + pushClass(item, 'toc_item'); + pushClass(item.firstElementChild, 'toc_link'); + }); + } + }); + + const current_toc = elem(`.${tocActive}`); + + if(current_toc) { + const page_internal_links = Array.from(elems('a', current_toc)); + + const page_ids = page_internal_links.map(function(link){ + return link.hash; + }); + + const link_positions = page_ids.map(function(id){ + const heading = document.getElementById(decodeURIComponent(id.replace('#',''))); + const position = heading.offsetTop; + return position; + }); + + page_internal_links.forEach(function(link, index){ + link.dataset.position = link_positions[index] + }); + + window.addEventListener('scroll', function(e) { + // this.setTimeout(function(){ + let position = window.scrollY; + let active = closestInt(position, link_positions); + activeHeading(active, page_internal_links); + // }, 1500) + }); + } + } + + elems('p').forEach(function(p){ + const buttons = elems('.button', p); + buttons.length > 1 ? pushClass(p, 'button_grid') : false; + }); +} + +function markExternalLinks() { + let links = elems('a'); + if(links) { + Array.from(links).forEach(function(link){ + let target, rel, blank, noopener, attr1, attr2, url, is_external; + url = new URL(link.href); + // definition of same origin: RFC 6454, section 4 (https://tools.ietf.org/html/rfc6454#section-4) + is_external = url.host !== location.host || url.protocol !== location.protocol || url.port !== location.port; + if(is_external) { + target = 'target'; + rel = 'rel'; + blank = '_blank'; + noopener = 'noopener'; + attr1 = elemAttribute(link, target); + attr2 = elemAttribute(link, noopener); + + attr1 ? false : elemAttribute(link, target, blank); + attr2 ? false : elemAttribute(link, rel, noopener); + } + }); + } +} + +function sanitizeURL(url) { + // removes any existing id on url + const position_of_hash = url.indexOf(hash); + if(position_of_hash > -1 ) { + const id = url.substr(position_of_hash, url.length - 1); + url = url.replace(id, ''); + } + return url +} + +function copyFeedback(parent) { + const copy_txt = document.createElement('div'); + const yanked = 'link_yanked'; + copy_txt.classList.add(yanked); + copy_txt.innerText = copied_text; + if(!elem(`.${yanked}`, parent)) { + const icon = parent.getElementsByTagName('svg')[0]; + const original_src = icon.src; + icon.src = '{{ absURL "icons/check.svg" }}'; + parent.appendChild(copy_txt); + setTimeout(function() { + parent.removeChild(copy_txt) + icon.src = original_src; + }, 2250); + } +} + +function copyHeadingLink() { + let deeplink, deeplinks, new_link, parent, target; + deeplink = 'link'; + deeplinks = elems(`.${deeplink}`); + if(deeplinks) { + document.addEventListener('click', function(event) + { + target = event.target; + parent = target.parentNode; + if (target && containsClass(target, deeplink) || containsClass(parent, deeplink)) { + event.preventDefault(); + new_link = target.href != undefined ? target.href : target.parentNode.href; + copyToClipboard(new_link); + target.href != undefined ? copyFeedback(target) : copyFeedback(target.parentNode); + } + }); + } +} + +function makeTablesResponsive() { + const tables = elems('table'); + if (tables) { + tables.forEach(function(table){ + const table_wrapper = createEl(); + pushClass(table_wrapper, 'scrollable'); + wrapEl(table, table_wrapper); + }); + } +} + +function backToTop(){ + const toTop = elem("#toTop"); + window.addEventListener("scroll", () => { + const last_known_scroll_pos = window.scrollY; + if(last_known_scroll_pos >= 200) { + toTop.style.display = "flex"; + pushClass(toTop, active); + } else { + deleteClass(toTop, active); + } + }); +} + +function lazyLoadMedia(elements = []) { + elements.forEach(element => { + let media_items = elems(element); + if(media_items) { + Array.from(media_items).forEach(function(item) { + item.loading = "lazy"; + }); + } + }) +} + +function loadActions() { + updateDate(); + customizeSidebar(); + markExternalLinks(); + copyHeadingLink(); + makeTablesResponsive(); + backToTop(); + + lazyLoadMedia(['iframe', 'img']); + + doc.addEventListener('click', event => { + let target = event.target; + let mode_class = 'color_choice'; + let is_mode_toggle = containsClass(target, mode_class); + is_mode_toggle ? setUserColorMode(true) : false; + toggleMenu(event); + }); +} + +window.addEventListener('load', loadActions()); diff --git a/assets/js/mode.js b/assets/js/mode.js new file mode 100644 index 0000000..404797d --- /dev/null +++ b/assets/js/mode.js @@ -0,0 +1,64 @@ +function prefersColor(mode){ + return `(prefers-color-scheme: ${mode})`; +} + +function systemMode() { + if (window.matchMedia) { + return window.matchMedia(prefersColor(dark)).matches ? dark : light; + } + return light; +} + +function currentMode() { + let acceptable_chars = light + dark; + acceptable_chars = [...acceptable_chars]; + let mode = getComputedStyle(doc).getPropertyValue(key).replace(/\"/g, '').trim(); + + return [...mode] + .filter(letter => acceptable_chars.includes(letter)) + .join(''); +} + +function changeMode(is_dark_mode) { + if(is_dark_mode) { + bank.setItem(storageKey, light) + elemAttribute(doc, mode_data, light); + } else { + bank.setItem(storageKey, dark); + elemAttribute(doc, mode_data, dark); + } +} + + +function pickModePicture(mode) { + elems('picture').forEach(function(picture){ + let source = picture.firstElementChild; + const picture_data = picture.dataset; + const images = [picture_data.lit, picture_data.dark]; + source.src = mode == 'dark' ? images[1] : images[0]; + }); +} + +function setMermaidTheme(mode) { + bank.setItem(mermaidThemeKey, mode); + let theme_input = elem('.color_choice'); + theme_input.value = mode; +} + +function setUserColorMode(mode = false) { + const is_dark_mode = currentMode() == dark; + const stored_mode = bank.getItem(storageKey); + const sys_mode = systemMode(); + if(stored_mode) { + mode ? changeMode(is_dark_mode) : elemAttribute(doc, mode_data, stored_mode); + } else { + mode === true ? changeMode(is_dark_mode) : changeMode(sys_mode!==dark); + } + const user_mode = doc.dataset.mode; + doc.dataset.systemmode = sys_mode; + user_mode ? pickModePicture(user_mode) : false; + + setMermaidTheme(user_mode); +} + +setUserColorMode(); \ No newline at end of file diff --git a/assets/js/search/algolia.js b/assets/js/search/algolia.js new file mode 100644 index 0000000..9df60f1 --- /dev/null +++ b/assets/js/search/algolia.js @@ -0,0 +1,2 @@ +/*! algoliasearch-lite.umd.js | 4.14.3 | © Algolia, inc. | https://github.com/algolia/algoliasearch-client-javascript */ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).algoliasearch=t()}(this,(function(){"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(r){for(var n=1;n=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function a(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return Promise.resolve().then((function(){var r=JSON.stringify(e),n=a()[r];return Promise.all([n||t(),void 0!==n])})).then((function(e){var t=o(e,2),n=t[0],a=t[1];return Promise.all([n,a||r.miss(n)])})).then((function(e){return o(e,1)[0]}))},set:function(e,t){return Promise.resolve().then((function(){var o=a();return o[JSON.stringify(e)]=t,n().setItem(r,JSON.stringify(o)),t}))},delete:function(e){return Promise.resolve().then((function(){var t=a();delete t[JSON.stringify(e)],n().setItem(r,JSON.stringify(t))}))},clear:function(){return Promise.resolve().then((function(){n().removeItem(r)}))}}}function i(e){var t=a(e.caches),r=t.shift();return void 0===r?{get:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},n=t();return n.then((function(e){return Promise.all([e,r.miss(e)])})).then((function(e){return o(e,1)[0]}))},set:function(e,t){return Promise.resolve(t)},delete:function(e){return Promise.resolve()},clear:function(){return Promise.resolve()}}:{get:function(e,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return r.get(e,n,o).catch((function(){return i({caches:t}).get(e,n,o)}))},set:function(e,n){return r.set(e,n).catch((function(){return i({caches:t}).set(e,n)}))},delete:function(e){return r.delete(e).catch((function(){return i({caches:t}).delete(e)}))},clear:function(){return r.clear().catch((function(){return i({caches:t}).clear()}))}}}function s(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{serializable:!0},t={};return{get:function(r,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},a=JSON.stringify(r);if(a in t)return Promise.resolve(e.serializable?JSON.parse(t[a]):t[a]);var u=n(),i=o&&o.miss||function(){return Promise.resolve()};return u.then((function(e){return i(e)})).then((function(){return u}))},set:function(r,n){return t[JSON.stringify(r)]=e.serializable?JSON.stringify(n):n,Promise.resolve(n)},delete:function(e){return delete t[JSON.stringify(e)],Promise.resolve()},clear:function(){return t={},Promise.resolve()}}}function c(e){for(var t=e.length-1;t>0;t--){var r=Math.floor(Math.random()*(t+1)),n=e[t];e[t]=e[r],e[r]=n}return e}function l(e,t){return t?(Object.keys(t).forEach((function(r){e[r]=t[r](e)})),e):e}function f(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n0?n:void 0,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}var m={Read:1,Write:2,Any:3},p=1,v=2,y=3;function g(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p;return r(r({},e),{},{status:t,lastUpdate:Date.now()})}function b(e){return"string"==typeof e?{protocol:"https",url:e,accept:m.Any}:{protocol:e.protocol||"https",url:e.url,accept:e.accept||m.Any}}var O="GET",P="POST";function q(e,t){return Promise.all(t.map((function(t){return e.get(t,(function(){return Promise.resolve(g(t))}))}))).then((function(e){var r=e.filter((function(e){return function(e){return e.status===p||Date.now()-e.lastUpdate>12e4}(e)})),n=e.filter((function(e){return function(e){return e.status===y&&Date.now()-e.lastUpdate<=12e4}(e)})),o=[].concat(a(r),a(n));return{getTimeout:function(e,t){return(0===n.length&&0===e?1:n.length+3+e)*t},statelessHosts:o.length>0?o.map((function(e){return b(e)})):t}}))}function w(e,t,n,o){var u=[],i=function(e,t){if(e.method===O||void 0===e.data&&void 0===t.data)return;var n=Array.isArray(e.data)?e.data:r(r({},e.data),t.data);return JSON.stringify(n)}(n,o),s=function(e,t){var n=r(r({},e.headers),t.headers),o={};return Object.keys(n).forEach((function(e){var t=n[e];o[e.toLowerCase()]=t})),o}(e,o),c=n.method,l=n.method!==O?{}:r(r({},n.data),o.data),f=r(r(r({"x-algolia-agent":e.userAgent.value},e.queryParameters),l),o.queryParameters),h=0,d=function t(r,a){var l=r.pop();if(void 0===l)throw{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:A(u)};var d={data:i,headers:s,method:c,url:S(l,n.path,f),connectTimeout:a(h,e.timeouts.connect),responseTimeout:a(h,o.timeout)},m=function(e){var t={request:d,response:e,host:l,triesLeft:r.length};return u.push(t),t},p={onSuccess:function(e){return function(e){try{return JSON.parse(e.content)}catch(t){throw function(e,t){return{name:"DeserializationError",message:e,response:t}}(t.message,e)}}(e)},onRetry:function(n){var o=m(n);return n.isTimedOut&&h++,Promise.all([e.logger.info("Retryable failure",x(o)),e.hostsCache.set(l,g(l,n.isTimedOut?y:v))]).then((function(){return t(r,a)}))},onFail:function(e){throw m(e),function(e,t){var r=e.content,n=e.status,o=r;try{o=JSON.parse(r).message}catch(e){}return function(e,t,r){return{name:"ApiError",message:e,status:t,transporterStackTrace:r}}(o,n,t)}(e,A(u))}};return e.requester.send(d).then((function(e){return function(e,t){return function(e){var t=e.status;return e.isTimedOut||function(e){var t=e.isTimedOut,r=e.status;return!t&&0==~~r}(e)||2!=~~(t/100)&&4!=~~(t/100)}(e)?t.onRetry(e):2==~~(e.status/100)?t.onSuccess(e):t.onFail(e)}(e,p)}))};return q(e.hostsCache,t).then((function(e){return d(a(e.statelessHosts).reverse(),e.getTimeout)}))}function j(e){var t={value:"Algolia for JavaScript (".concat(e,")"),add:function(e){var r="; ".concat(e.segment).concat(void 0!==e.version?" (".concat(e.version,")"):"");return-1===t.value.indexOf(r)&&(t.value="".concat(t.value).concat(r)),t}};return t}function S(e,t,r){var n=T(r),o="".concat(e.protocol,"://").concat(e.url,"/").concat("/"===t.charAt(0)?t.substr(1):t);return n.length&&(o+="?".concat(n)),o}function T(e){return Object.keys(e).map((function(t){return f("%s=%s",t,(r=e[t],"[object Object]"===Object.prototype.toString.call(r)||"[object Array]"===Object.prototype.toString.call(r)?JSON.stringify(e[t]):e[t]));var r})).join("&")}function A(e){return e.map((function(e){return x(e)}))}function x(e){var t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return r(r({},e),{},{request:r(r({},e.request),{},{headers:r(r({},e.request.headers),t)})})}var N=function(e){var t=e.appId,n=function(e,t,r){var n={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers:function(){return e===h.WithinHeaders?n:{}},queryParameters:function(){return e===h.WithinQueryParameters?n:{}}}}(void 0!==e.authMode?e.authMode:h.WithinHeaders,t,e.apiKey),a=function(e){var t=e.hostsCache,r=e.logger,n=e.requester,a=e.requestsCache,u=e.responsesCache,i=e.timeouts,s=e.userAgent,c=e.hosts,l=e.queryParameters,f={hostsCache:t,logger:r,requester:n,requestsCache:a,responsesCache:u,timeouts:i,userAgent:s,headers:e.headers,queryParameters:l,hosts:c.map((function(e){return b(e)})),read:function(e,t){var r=d(t,f.timeouts.read),n=function(){return w(f,f.hosts.filter((function(e){return 0!=(e.accept&m.Read)})),e,r)};if(!0!==(void 0!==r.cacheable?r.cacheable:e.cacheable))return n();var a={request:e,mappedRequestOptions:r,transporter:{queryParameters:f.queryParameters,headers:f.headers}};return f.responsesCache.get(a,(function(){return f.requestsCache.get(a,(function(){return f.requestsCache.set(a,n()).then((function(e){return Promise.all([f.requestsCache.delete(a),e])}),(function(e){return Promise.all([f.requestsCache.delete(a),Promise.reject(e)])})).then((function(e){var t=o(e,2);t[0];return t[1]}))}))}),{miss:function(e){return f.responsesCache.set(a,e)}})},write:function(e,t){return w(f,f.hosts.filter((function(e){return 0!=(e.accept&m.Write)})),e,d(t,f.timeouts.write))}};return f}(r(r({hosts:[{url:"".concat(t,"-dsn.algolia.net"),accept:m.Read},{url:"".concat(t,".algolia.net"),accept:m.Write}].concat(c([{url:"".concat(t,"-1.algolianet.com")},{url:"".concat(t,"-2.algolianet.com")},{url:"".concat(t,"-3.algolianet.com")}]))},e),{},{headers:r(r(r({},n.headers()),{"content-type":"application/x-www-form-urlencoded"}),e.headers),queryParameters:r(r({},n.queryParameters()),e.queryParameters)}));return l({transporter:a,appId:t,addAlgoliaAgent:function(e,t){a.userAgent.add({segment:e,version:t})},clearCache:function(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then((function(){}))}},e.methods)},C=function(e){return function(t,r){return t.method===O?e.transporter.read(t,r):e.transporter.write(t,r)}},k=function(e){return function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={transporter:e.transporter,appId:e.appId,indexName:t};return l(n,r.methods)}},J=function(e){return function(t,n){var o=t.map((function(e){return r(r({},e),{},{params:T(e.params||{})})}));return e.transporter.read({method:P,path:"1/indexes/*/queries",data:{requests:o},cacheable:!0},n)}},E=function(e){return function(t,o){return Promise.all(t.map((function(t){var a=t.params,u=a.facetName,i=a.facetQuery,s=n(a,["facetName","facetQuery"]);return k(e)(t.indexName,{methods:{searchForFacetValues:R}}).searchForFacetValues(u,i,r(r({},o),s))})))}},I=function(e){return function(t,r,n){return e.transporter.read({method:P,path:f("1/answers/%s/prediction",e.indexName),data:{query:t,queryLanguages:r},cacheable:!0},n)}},F=function(e){return function(t,r){return e.transporter.read({method:P,path:f("1/indexes/%s/query",e.indexName),data:{query:t},cacheable:!0},r)}},R=function(e){return function(t,r,n){return e.transporter.read({method:P,path:f("1/indexes/%s/facets/%s/query",e.indexName,t),data:{facetQuery:r},cacheable:!0},n)}},D=1,W=2,H=3;function Q(e,t,n){var o,a={appId:e,apiKey:t,timeouts:{connect:1,read:2,write:30},requester:{send:function(e){return new Promise((function(t){var r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach((function(t){return r.setRequestHeader(t,e.headers[t])}));var n,o=function(e,n){return setTimeout((function(){r.abort(),t({status:0,content:n,isTimedOut:!0})}),1e3*e)},a=o(e.connectTimeout,"Connection timeout");r.onreadystatechange=function(){r.readyState>r.OPENED&&void 0===n&&(clearTimeout(a),n=o(e.responseTimeout,"Socket timeout"))},r.onerror=function(){0===r.status&&(clearTimeout(a),clearTimeout(n),t({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=function(){clearTimeout(a),clearTimeout(n),t({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)}))}},logger:(o=H,{debug:function(e,t){return D>=o&&console.debug(e,t),Promise.resolve()},info:function(e,t){return W>=o&&console.info(e,t),Promise.resolve()},error:function(e,t){return console.error(e,t),Promise.resolve()}}),responsesCache:s(),requestsCache:s({serializable:!1}),hostsCache:i({caches:[u({key:"".concat("4.14.3","-").concat(e)}),s()]}),userAgent:j("4.14.3").add({segment:"Browser",version:"lite"}),authMode:h.WithinQueryParameters};return N(r(r(r({},a),n),{},{methods:{search:J,searchForFacetValues:E,multipleQueries:J,multipleSearchForFacetValues:E,customRequest:C,initIndex:function(e){return function(t){return k(e)(t,{methods:{search:F,searchForFacetValues:R,findAnswers:I}})}}}}))}return Q.version="4.14.3",Q})); \ No newline at end of file diff --git a/assets/js/search/fuse.js b/assets/js/search/fuse.js new file mode 100644 index 0000000..7def598 --- /dev/null +++ b/assets/js/search/fuse.js @@ -0,0 +1,9 @@ +/** + * Fuse.js v6.4.6 - Lightweight fuzzy-search (http://fusejs.io) + * + * Copyright (c) 2021 Kiro Risk (http://kiro.me) + * All Rights Reserved. Apache Software License 2.0 + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ +var e,t;e=this,t=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:3,t=new Map,n=Math.pow(10,e);return{get:function(e){var r=e.match(I).length;if(t.has(r))return t.get(r);var i=1/Math.sqrt(r),o=parseFloat(Math.round(i*n)/n);return t.set(r,o),o},clear:function(){t.clear()}}}var E=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.getFn,i=void 0===r?A.getFn:r;t(this,e),this.norm=C(3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return r(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=t,this._keysMap={},t.forEach((function(t,n){e._keysMap[t.id]=n}))}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,g(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();g(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?A.getFn:r,o=new E({getFn:i});return o.setKeys(e.map(_)),o.setSources(t),o.create(),o}function R(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,u=void 0===s?A.distance:s,h=t.ignoreLocation,f=void 0===h?A.ignoreLocation:h,l=r/e.length;if(f)return l;var d=Math.abs(a-o);return u?l+d/u:d?1:l}function F(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:A.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}function P(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?A.location:o,a=i.threshold,s=void 0===a?A.threshold:a,u=i.distance,h=void 0===u?A.distance:u,f=i.includeMatches,l=void 0===f?A.includeMatches:f,d=i.findAllMatches,v=void 0===d?A.findAllMatches:d,g=i.minMatchCharLength,y=void 0===g?A.minMatchCharLength:g,p=i.isCaseSensitive,m=void 0===p?A.isCaseSensitive:p,k=i.ignoreLocation,M=void 0===k?A.ignoreLocation:k;if(t(this,e),this.options={location:c,threshold:s,distance:h,includeMatches:l,findAllMatches:v,minMatchCharLength:y,isCaseSensitive:m,ignoreLocation:M},this.pattern=m?n:n.toLowerCase(),this.chunks=[],this.pattern.length){var b=function(e,t){r.chunks.push({pattern:e,alphabet:P(e),startIndex:t})},x=this.pattern.length;if(x>32){for(var L=0,S=x%32,w=x-S;L3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?A.location:i,c=r.distance,a=void 0===c?A.distance:c,s=r.threshold,u=void 0===s?A.threshold:s,h=r.findAllMatches,f=void 0===h?A.findAllMatches:h,l=r.minMatchCharLength,d=void 0===l?A.minMatchCharLength:l,v=r.includeMatches,g=void 0===v?A.includeMatches:v,y=r.ignoreLocation,p=void 0===y?A.ignoreLocation:y;if(t.length>32)throw new Error(L(32));for(var m,k=t.length,M=e.length,b=Math.max(0,Math.min(o,M)),x=u,S=b,w=d>1||g,_=w?Array(M):[];(m=e.indexOf(t,S))>-1;){var O=R(t,{currentLocation:m,expectedLocation:b,distance:a,ignoreLocation:p});if(x=Math.min(O,x),S=m+k,w)for(var j=0;j=K;J-=1){var T=J-1,U=n[e.charAt(T)];if(w&&(_[T]=+!!U),W[J]=(W[J+1]<<1|1)&U,P&&(W[J]|=(I[J+1]|I[J])<<1|1|I[J+1]),W[J]&$&&(C=R(t,{errors:P,currentLocation:T,expectedLocation:b,distance:a,ignoreLocation:p}))<=x){if(x=C,(S=T)<=b)break;K=Math.max(1,2*b-S)}}var V=R(t,{errors:P+1,currentLocation:b,expectedLocation:b,distance:a,ignoreLocation:p});if(V>x)break;I=W}var B={isMatch:S>=0,score:Math.max(.001,C)};if(w){var G=F(_,d);G.length?g&&(B.indices=G):B.isMatch=!1}return B}(e,n,i,{location:c+o,distance:a,threshold:s,findAllMatches:u,minMatchCharLength:h,includeMatches:r,ignoreLocation:f}),p=y.isMatch,m=y.score,k=y.indices;p&&(g=!0),v+=m,p&&k&&(d=[].concat(l(d),l(k)))}));var y={isMatch:g,score:g?v/this.chunks.length:1};return g&&r&&(y.indices=d),y}}]),e}(),D=function(){function e(n){t(this,e),this.pattern=n}return r(e,[{key:"search",value:function(){}}],[{key:"isMultiMatch",value:function(e){return z(e,this.multiRegex)}},{key:"isSingleMatch",value:function(e){return z(e,this.singleRegex)}}]),e}();function z(e,t){var n=e.match(t);return n?n[1]:null}var K=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"exact"}},{key:"multiRegex",get:function(){return/^="(.*)"$/}},{key:"singleRegex",get:function(){return/^=(.*)$/}}]),i}(D),q=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"$/}},{key:"singleRegex",get:function(){return/^!(.*)$/}}]),i}(D),W=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}}],[{key:"type",get:function(){return"prefix-exact"}},{key:"multiRegex",get:function(){return/^\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^\^(.*)$/}}]),i}(D),J=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-prefix-exact"}},{key:"multiRegex",get:function(){return/^!\^"(.*)"$/}},{key:"singleRegex",get:function(){return/^!\^(.*)$/}}]),i}(D),T=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}],[{key:"type",get:function(){return"suffix-exact"}},{key:"multiRegex",get:function(){return/^"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^(.*)\$$/}}]),i}(D),U=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){var t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}}],[{key:"type",get:function(){return"inverse-suffix-exact"}},{key:"multiRegex",get:function(){return/^!"(.*)"\$$/}},{key:"singleRegex",get:function(){return/^!(.*)\$$/}}]),i}(D),V=function(e){a(i,e);var n=f(i);function i(e){var r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,a=void 0===c?A.location:c,s=o.threshold,u=void 0===s?A.threshold:s,h=o.distance,f=void 0===h?A.distance:h,l=o.includeMatches,d=void 0===l?A.includeMatches:l,v=o.findAllMatches,g=void 0===v?A.findAllMatches:v,y=o.minMatchCharLength,p=void 0===y?A.minMatchCharLength:y,m=o.isCaseSensitive,k=void 0===m?A.isCaseSensitive:m,M=o.ignoreLocation,b=void 0===M?A.ignoreLocation:M;return t(this,i),(r=n.call(this,e))._bitapSearch=new N(e,{location:a,threshold:u,distance:f,includeMatches:d,findAllMatches:g,minMatchCharLength:p,isCaseSensitive:k,ignoreLocation:b}),r}return r(i,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),i}(D),B=function(e){a(i,e);var n=f(i);function i(e){return t(this,i),n.call(this,e)}return r(i,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}],[{key:"type",get:function(){return"include"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),i}(D),G=[K,B,W,J,U,T,q,V],H=G.length,Q=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;function X(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(Q).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i1&&void 0!==arguments[1]?arguments[1]:{},i=r.isCaseSensitive,o=void 0===i?A.isCaseSensitive:i,c=r.includeMatches,a=void 0===c?A.includeMatches:c,s=r.minMatchCharLength,u=void 0===s?A.minMatchCharLength:s,h=r.ignoreLocation,f=void 0===h?A.ignoreLocation:h,l=r.findAllMatches,d=void 0===l?A.findAllMatches:l,v=r.location,g=void 0===v?A.location:v,y=r.threshold,p=void 0===y?A.threshold:y,m=r.distance,k=void 0===m?A.distance:m;t(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:a,minMatchCharLength:u,findAllMatches:d,ignoreLocation:f,location:g,threshold:p,distance:k},this.pattern=o?n:n.toLowerCase(),this.query=X(this.pattern,this.options)}return r(e,[{key:"searchIn",value:function(e){var t=this.query;if(!t)return{isMatch:!1,score:1};var n=this.options,r=n.includeMatches;e=n.isCaseSensitive?e:e.toLowerCase();for(var i=0,o=[],c=0,a=0,s=t.length;a-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function le(e,t){t.score=e.score}function de(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?A.includeMatches:r,o=n.includeScore,c=void 0===o?A.includeScore:o,a=[];return i&&a.push(fe),c&&a.push(le),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}var ve=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;t(this,e),this.options=c({},A,{},r),this.options.useExtendedSearch,this._keyStore=new w(this.options.keys),this.setCollection(n,i)}return r(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof E))throw new Error("Incorrect 'index' type");this._myIndex=t||$(this.options.keys,this._docs,{getFn:this.options.getFn})}},{key:"add",value:function(e){k(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{},n=t.limit,r=void 0===n?-1:n,i=this.options,o=i.includeMatches,c=i.includeScore,a=i.shouldSort,s=i.sortFn,u=i.ignoreFieldNorm,h=g(e)?g(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return he(h,{ignoreFieldNorm:u}),a&&h.sort(s),y(r)&&r>-1&&(h=h.slice(0,r)),de(h,this._docs,{includeMatches:o,includeScore:c})}},{key:"_searchStringList",value:function(e){var t=te(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(k(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,u=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.auto,i=void 0===r||r,o=function e(n){var r=Object.keys(n),o=ae(n);if(!o&&r.length>1&&!ce(n))return e(ue(n));if(se(n)){var c=o?n[ie]:r[0],a=o?n[oe]:n[c];if(!g(a))throw new Error(x(c));var s={keyId:j(c),pattern:a};return i&&(s.searcher=te(a,t)),s}var u={children:[],operator:r[0]};return r.forEach((function(t){var r=n[t];v(r)&&r.forEach((function(t){u.children.push(e(t))}))})),u};return ce(e)||(e=ue(e)),o(e)}(e,this.options),r=this._myIndex.records,i={},o=[];return r.forEach((function(e){var r=e.$,c=e.i;if(k(r)){var a=function e(n,r,i){if(!n.children){var o=n.keyId,c=n.searcher,a=t._findMatches({key:t._keyStore.get(o),value:t._myIndex.getValueForItemAtKeyId(r,o),searcher:c});return a&&a.length?[{idx:i,item:r,matches:a}]:[]}switch(n.operator){case ne:for(var s=[],u=0,h=n.children.length;u1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?A.getFn:n,i=e.keys,o=e.records,c=new E({getFn:r});return c.setKeys(i),c.setIndexRecords(o),c},ve.config=A,function(){ee.push.apply(ee,arguments)}(Z),ve},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Fuse=t(); \ No newline at end of file diff --git a/assets/js/search/index.js b/assets/js/search/index.js new file mode 100644 index 0000000..60c5e73 --- /dev/null +++ b/assets/js/search/index.js @@ -0,0 +1,255 @@ +function minQueryLen(query) { + query = query.trim(); + const query_is_float = parseFloat(query); + const min_query_length = query_is_float ? 1 : 2; + return min_query_length; +} + +function findQuery(query = 'query') { + const url_params = new URLSearchParams(window.location.search); + return url_params.has(query) ? url_params.get(query) : empty_string; +} + +function search(index, scope = null, passive = false) { + scope = search_scope_global ? null : scope; + if(search_term.length) { + let raw_results = index; + if(!algolia_config.on) { + raw_results = index.search(search_term); + raw_results = raw_results.map(function(result){ + const score = result.score; + const result_item = result.item; + result_item.score = (parseFloat(score) * 50).toFixed(0); + return result_item; + }) + } + + if(scope) { + raw_results = raw_results.filter(result_item => { + return result_item.section == scope; + }); + } + + passive ? searchResults(raw_results, search_term, true) : searchResults(raw_results, search_term); + + } else { + passive ? searchResults([], empty_string, true) : searchResults(); + } +} + +function liveSearch(index) { + if (search_field) { + let search_scope = search_field.dataset.scope; + search(index, search_scope); + search_scope = search_scope_global ? null : search_scope; + if(!search_page_element) { + search_field.addEventListener('keyup', function(event){ + search_term = search_field.value.trim().toLowerCase(); + if(search_term.length && event.keyCode === 13) { + const scope_parameter = search_scope ? `&scope=${search_scope}` : empty_string; + window.location.href = new URL(`search/?query=${search_term}${ scope_parameter }`, root_url).href; + } + }); + } + } +} + +function searchResults(results=[], query=empty_string, passive = false) { + let results_fragment = new DocumentFragment(); + let show_results = elem('.search_results'); + if(passive || search_page_element) { + show_results = search_page_element; + } + emptyEl(show_results); + + const query_len = query.length; + const required_query_len = minQueryLen(query); + + if(results.length && query_len >= required_query_len) { + let results_title = createEl('h3'); + results_title.className = 'search_title'; + results_title.innerText = quick_links; + + let go_back_button = createEl('button'); + go_back_button.textContent = 'Go Back'; + go_back_button.className = go_back_class; + if(passive) { + results_title.innerText = search_results_label; + } + if(!search_page_element) { + results = results.slice(0,8); + } else { + // results_fragment.appendChild(go_back_button); + results = results.slice(0,12); + } + results_fragment.appendChild(results_title); + + results.forEach(function(result){ + let item = createEl('a'); + item.href = `${result.link}?query=${query}`; + item.className = search_result_class; + item.style.order = result.score; + if (passive) { + pushClass(item, 'passive'); + let item_title = createEl('h3'); + item_title.textContent = result.title; + item.appendChild(item_title); + + let item_description = createEl('p'); + // position of first search term instance + let query_instance = result.body.indexOf(query); + item_description.textContent = `${result.body.substring(query_instance, query_instance + 200)}`; + item.appendChild(item_description); + } else { + item.textContent = result.title; + } + results_fragment.appendChild(item); + }); + } + + if(show_results) { + let results_title_contents = empty_string; + if(query_len >= required_query_len) { + results_title_contents = !results.length ? + `${no_matches_found}` : empty_string; + } else { + results_title_contents = `` + } + + show_results.innerHTML = results_title_contents; + + show_results.appendChild(results_fragment); + } +} + +function passiveSearch(index) { + if(search_page_element) { + search_term = findQuery(); + const search_scope = findQuery('scope'); + search(index, search_scope, true); + } +} + +function hasSearchResults() { + const results = elem('.results'); + return results ? [results, results.innerHTML.length] : false; +} + +function clearSearchResults() { + let results = hasSearchResults(); + if(results) { + results = results[0]; + results.innerHTML = empty_string; + elem(search_field_class).value = empty_string; + } +} + +function onEscape(fn){ + window.addEventListener('keydown', event => event.code === "Escape" ? fn() : false); +} + +function initFuseSearch(manual = true) { + const page_language = document.documentElement.lang; + const search_index = `${ page_language === 'en' ? empty_string : page_language}/index.json`; + fetch(new URL(search_index, root_url).href) + .then(response => response.json()) + .then(function(search_data) { + search_data = search_data.length ? search_data : []; + const fuse_index = new Fuse(search_data, search_options); + manual ? liveSearch(fuse_index) : passiveSearch(fuse_index); + }) + .catch((error) => console.error(error)); +} + +function initAlgoliaSearch(manual = true) { + const algolia_client = algoliasearch(algolia_config.id, algolia_config.key); + const algolia_index = algolia_client.initIndex(algolia_config.index); + algolia_index.search(search_term, { + attributesToRetrieve: search_keys.slice(0,5), + hitsPerPage: 12, + }).then(({ hits }) => { + manual ? liveSearch(hits) : passiveSearch(hits); + }); +} + +function tabOverSearchResults() { + search_field.addEventListener('keydown', function (e) { + // Prevent curet from moving when up or down is pressed + if (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 13) { + e.preventDefault(); + return; + } + }); + search_field.addEventListener('keyup', function (e) { + if (e.keyCode !== 38 && e.keyCode !== 40 && e.keyCode !== 13) { + return + } + e.preventDefault(); + + var results = e.target.parentNode.getElementsByClassName('search_result'); + if (results.length === 0) { + return; + } + + // Find the currently selected result and select the next or previous one + var selected = -1; + for (var i = 0; i < results.length; i++) { + if (results[i].classList.contains('active')) { + selected = i; + results[i].classList.remove('active'); + break; + } + } + + if (e.keyCode === 38) { + // For up arrow select the previous result + selected = selected === -1 ? results.length - 1 : selected - 1; + if (selected < 0) { + selected = results.length - 1; + } + + results[selected].classList.add('active'); + return; + } else if (e.keyCode === 40) { + // For down arrow select the next result + selected = selected === -1 ? 0 : selected + 1; + if (selected === results.length) { + selected = 0; + } + + results[selected].classList.add('active'); + return; + } + + window.location.href = results[selected === -1 ? 0 : selected].href; + return; + }); +} + +function initializeSearch() { + let main = elem('main'); + main = main ? main : elem('.main'); + + search_field.addEventListener('input', function() { + search_term = search_field.value.trim().toLowerCase(); + algolia_config.on ? initAlgoliaSearch() : initFuseSearch(); + }); + + if (search_page_element) { + algolia_config.on ? initAlgoliaSearch(false) : initFuseSearch(false); + } + + wrapText(findQuery(), main); + + onEscape(clearSearchResults); + + window.addEventListener('click', function(event){ + const target = event.target; + const is_search = target.closest(search_class) || target.matches(search_class); + !is_search && !search_page_element ? clearSearchResults() : false; + }); + + tabOverSearchResults(); +} + +window.addEventListener('load', () => initializeSearch()); diff --git a/assets/js/search/variables.js b/assets/js/search/variables.js new file mode 100644 index 0000000..7b0b6a6 --- /dev/null +++ b/assets/js/search/variables.js @@ -0,0 +1,37 @@ +const search_result_class = 'search_result'; +const empty_string = ''; +const search_field_class = '.search_field'; +const search_class = '.search'; +let search_term = empty_string; +const search_field = elem(search_field_class); + +// values defined under config/_default/params.toml +let other_searchable_fields = '{{ delimit (default slice site.Params.otherSearchableFields) ", " }}' + +if(other_searchable_fields.length > 2) { + other_searchable_fields = other_searchable_fields + .split(",") + .map(search_value => search_value.toLowerCase().trim()); +} else { + other_searchable_fields = []; +} + +const search_page_element = elem('#searchpage'); +let search_scope_global = `{{ trim site.Params.search.global " " }}`; +search_scope_global = search_scope_global == 'true' ? true : false; + +// Fuse specific +let search_keys = ['body', 'title', 'link', 'section', 'id',]; +search_keys = search_keys.concat(other_searchable_fields); + +const search_options = { + ignoreLocation: true, + findAllMatches: true, + includeScore: true, + shouldSort: true, + keys: search_keys, + threshold: 0.1 +}; + +// Algolia specific +const algolia_config = JSON.parse(`{{ partialCached "functions/getAlgoliaConfig" . }}`); diff --git a/assets/js/variables.js b/assets/js/variables.js new file mode 100644 index 0000000..f08fabc --- /dev/null +++ b/assets/js/variables.js @@ -0,0 +1,43 @@ +'use strict'; + +const doc = document.documentElement; +const toggle_id = 'toggle'; +const show_id = 'show'; +const menu = 'menu'; +const active = 'active'; +let site_title = `{{ replace (lower site.Title) " " "-" }}`; +let root_url = '{{ strings.TrimSuffix "/" .Site.BaseURL }}/'; +root_url = root_url.startsWith('http') ? root_url : window.location.origin; + +const go_back_class = 'button_back'; +const line_class = '.line'; + +// config defined values +const code_block_config = JSON.parse('{{ partial "functions/getCodeConfig" . }}'); +const iconsPath = `{{ partialCached "functions/getIconPath" . }}`; + +const shell_based = ['sh', 'shell', 'zsh', 'bash']; + +const body = elem('body'); +const max_lines = code_block_config.maximum; +const show_lines = code_block_config.show; +const copy_id = 'panel_copy'; +const wrap_id = 'panel_wrap'; +const lines_id = 'panel_lines'; +const panel_expand = 'panel_expand'; +const panel_expanded = 'panel_expanded'; +const panel_box = 'panel_box'; +const panel_hide = 'panel_hide'; +const panel_from = 'panel_from'; +const full_height = 'initial'; +const highlight = 'highlight'; +const highlight_wrap = 'highlight_wrap' +const hash = '#'; + +const light = 'light'; +const dark = 'dark'; +const storageKey = `${site_title}-color-mode`; +const mermaidThemeKey = `${site_title}-mermaid`; +const key = '--color-mode'; +const mode_data = 'data-mode'; +const bank = window.localStorage; diff --git a/assets/sass/_base.sass b/assets/sass/_base.sass new file mode 100644 index 0000000..d32c1d9 --- /dev/null +++ b/assets/sass/_base.sass @@ -0,0 +1,277 @@ +* + box-sizing: border-box + margin: 0 + padding: 0 + scrollbar-color: var(--scroll-thumb) transparent + scrollbar-width: thin + +::-webkit-scrollbar + width: .5rem + +::-webkit-scrollbar-thumb + background: var(--scroll-thumb) + border-radius: .25rem + +body, html + scroll-behavior: smooth + scroll-padding-top: 1rem + font-kerning: normal + -webkit-text-size-adjust: 100% + font-size: 18px + +@keyframes flash + 0% + opacity: 0 + 75% + opacity: 0 + 100% + opacity: 1 + +body + font-family: var(--font) + background-color: var(--bg) + color: var(--text) + line-height: 1.5 + margin: 0 auto + position: relative + font-kerning: normal + display: flex + min-width: 0 + flex-direction: column + justify-content: space-between + min-height: 100vh + -webkit-font-smoothing: antialiased + -moz-osx-font-smoothing: grayscale + -webkit-overflow-scrolling: touch + max-width: 1440px + animation: 0.67s flash ease-in + + @media screen and (min-width: 1640px) + max-width: 1600px + +a + text-decoration: none + color: inherit +p + padding: 0.75rem 0 + // opacity: 0.9 + &:empty + display: none +li + &, p + padding: 0.25rem 0 +blockquote + opacity: 0.8 + padding: 1rem + position: relative + quotes: '\201C''\201D''\2018''\2019' + margin: 0.75rem 0 + display: flex + flex-flow: row wrap + background-repeat: no-repeat + background-size: 5rem + background-position: 50% 50% + position: relative + background-color: var(--accent) + border-radius: 0.25rem + overflow: hidden + &::before + content: "" + padding: 2px + position: absolute + top: 0 + bottom: 0 + left: 0 + background: var(--theme) + + p + padding-left: 0.5rem !important + font-size: 1.1rem !important + width: 100% + font-style: italic + +h1,h2,h3,h4,h5 + font-family: inherit + font-weight: 500 + padding: 0.33rem 0 + color: inherit + line-height: 1.35 + +h1 + font-size: 200% +h2 + font-size: 175% +h3 + font-size: 150% +h4 + font-size: 125% +h5 + font-size: 120% +h6 + font-size: 100% + +img, svg, figure + max-width: 100% + vertical-align: middle +img + height: auto + margin: 1rem auto + padding: 0 + +main + flex: 1 + @media screen and (min-width: 42rem) + padding-bottom: 45px + +ol, ul + list-style: none + +b, strong + font-weight: 500 + +hr + border: none + padding: 1px + background: var(--border-color) + margin: 1rem 0 + +.aside + overflow-y: auto + background: var(--bg) + border-radius: 0.25rem + align-self: start + max-height: 80vh + position: sticky + z-index: 9999 + top: 0 + padding: 1rem 0 + @media screen and (min-width: 42rem) + padding: 1rem 1.5rem + top: 2.5rem + margin-top: 1rem + padding-top: 0 + &_inner + height: 0 + overflow: hidden + @media screen and (min-width: 42rem) + height: initial + &.show &_inner + height: initial + overflow: visible + &_toggle + padding: 0.5rem 1.5rem + border-radius: 0.5rem + background: var(--accent) + transform: translateY(-1rem) + display: flex + justify-content: space-between + @media screen and (min-width: 42rem) + display: none + h3 + position: relative + ul + padding: 0 + list-style: none + +th, td + padding: 0.5rem + font-weight: 400 !important + &:not(:first-child) + padding-left: 1.5rem + +thead + background: var(--theme) + color: var(--light) + font-weight: 400 + text-align: left + +tbody + tr + &:nth-child(even) + background-color: var(--accent) !important + box-shadow: 0 1rem 0.75rem -0.75rem rgba(0,0,0,0.07) + +table + margin: 1.5rem 0 + width: 100% + +.main + flex: 1 + > .grid-auto + @media screen and (max-width: 667px) + grid-gap: 0 + +.page + &-home + h1 + font-weight: 300 + +.content + ul, ol + padding-left: 1.1rem + ul + list-style: initial + ol + list-style: decimal + a:not(.button) + color: var(--theme) + +::placeholder + font-size: 1rem + +svg + &.icon_sort + fill: var(--light) + height: 0.7rem + width: 0.7rem + display: inline-block + margin-left: auto + vertical-align: middle + +canvas + margin: 2.5rem auto 0 auto + max-width: 450px !important + max-height: 450px !important + +footer + min-height: 150px + +del + opacity: 0.5 + +#toTop + background: transparent + outline: 0.5rem solid transparent + height: 2rem + width: 2rem + cursor: pointer + padding: 0.5rem + display: flex + align-items: center + justify-content: center + position: fixed + right: 0 + bottom: 2.25rem + transform: rotate(45deg) translate(5rem) + opacity: 0 + transition: opacity 0.5s var(--ease), transform 0.25s var(--ease) + z-index: 5 + &.active + right: 1.5rem + opacity: 1 + transform: rotate(45deg) translate(0) + &::after, &::before + position: absolute + display: block + width: 1rem + height: 1rem + content: "" + border-left: 1px solid var(--text) + border-top: 1px solid var(--text) + &::after + width: 0.67rem + height: 0.67rem + transform: translate(0.1rem, 0.1rem) + +#searchpage + padding-top: 5rem diff --git a/assets/sass/_blog.sass b/assets/sass/_blog.sass new file mode 100644 index 0000000..918453c --- /dev/null +++ b/assets/sass/_blog.sass @@ -0,0 +1,306 @@ +@mixin shadow($opacity: 0.17) + box-shadow: 0 0 3rem rgba(0,0,0,$opacity) + &:hover + box-shadow: 0 0 5rem rgba(0,0,0, (1.5 * $opacity)) + +.post + margin: 0 auto + width: 100% + p, h1, h2, h3, h4, h5, h6, blockquote, ol, ul, .highlight_wrap, hr + max-width: 840px !important + margin-left: auto + margin-right: auto + + img:not(.icon) + @media screen and (min-width: 1025px) + display: block + width: 100vw + max-width: 1024px + margin-left: auto + margin-right: auto + + h2,h3,h4 + margin: 0.5rem auto + text-align: left + padding: 5px 0 0 0 + + p + padding-bottom: 0.5rem + padding-top: 0.5rem + font-size: 1.05rem + + &s + display: flex + justify-content: space-between + flex-flow: row wrap + width: 100% + align-items: stretch + + &s:not(.aside) + padding: 0 30px + + ol + padding: 1rem 1.25rem + + &_body + img + width: 100% + max-width: 100% + &_inner + a + color: var(--theme) + transition: all 0.3s + &:hover + opacity: 0.8 + text-decoration: underline + + img:not(.icon) + margin-bottom: 2rem + box-shadow: 0 1.5rem 1rem -1rem rgba(0,0,0,0.25) + ~ h1, ~ h2, ~ h3, ~ h4 + margin-top: 0 + padding-top: 0 + + .icon + margin-top: 0 + margin-bottom: 0 + + &_date + color: var(--theme) + + &_copy + opacity: 0 + transition: opacity 0.3s ease-out + + &_item + @include shadow + margin: 1.25rem 0 + border-radius: 10px + overflow: hidden + width: 100% + @media screen and (min-width:667px) + width: 47% + + &_item:hover &_copy + opacity: 1 + + &_link + padding: 2.5px 0 + font-size: 1.25em + margin: 2.5px 0 + text-align: left + + &_meta + overflow: hidden + opacity: 0.8 + font-size: 0.84rem + font-weight: 500 + display: inline-grid + grid-template-columns: auto 1fr + background-color: var(--light) + padding: 0 + align-items: center + border-radius: 0.3rem + color: var(--dark) + text-transform: capitalize + a + &:hover + color: var(--theme) + text-decoration: underline + opacity: 0.9 + + &_extra + display: flex + justify-content: flex-end + + &_tag + font-size: 0.75rem !important + font-weight: 500 + background: var(--theme) + color: var(--light) + padding: 0.25rem 0.67rem !important + text-transform: uppercase + display: inline-flex + border-radius: 5px + + &_title + margin: 1.75rem 0 1rem + + &_time + background: var(--theme) + display: inline-grid + padding: 0.2rem 0.75rem + color: var(--light) + + &_thumbnail + width: 100% + margin: 0 + + &_nav + padding: 3rem 1.5rem + display: grid + margin: 2.25rem auto 1rem + text-align: center + color: var(--theme) + // box-shadow: 0 1rem 3rem -1rem rgba(0,0,0,0.15) + text-transform: uppercase + &, span + position: relative + z-index: 3 + + &::before + content: "" + position: absolute + background: var(--accent) + top: 0 + left: 0 + bottom: 0 + right: 0 + z-index: 1 + border-radius: 1rem + + &_next + display: inline-grid + margin: 0 auto + width: 10rem + grid-template-columns: 1fr 1.33rem + &::after + content: "" + background-image: var(--next-icon-path) + background-repeat: repeat no-repeat + background-size: 0.8rem + background-position: center right + +// .pager +// display: grid +// grid-template-columns: 2.5rem 1fr 2.5rem +// margin: 2rem auto 0 +// max-width: 12.5rem +// &, &_item +// justify-content: center +// align-items: center + +// &_item +// height: 2.5rem +// width: 2.5rem +// display: inline-flex +// margin-left: 5px +// margin-right: 5px +// background-color: var(--accent) +// color: var(--light) +// border-radius: 50% +// &:hover +// opacity: 0.5 + +// span +// text-align: center + +.excerpt + padding: 0 10px 1.5rem 10px + position: relative + z-index: 1 + &_meta + display: flex + justify-content: space-between + align-items: center + transform: translateY(-2.5rem) + position: relative + z-index: 5 + +.archive + &_item + display: grid + padding: 1.5rem 0 + + &_title + margin: 0 + +.article + box-shadow: 0 0.5rem 2rem rgba(0,0,0,0.12) + overflow: hidden + border-radius: 0.5rem + &_title + margin: 0 + &_excerpt + &:not(.visible) + height: 0 + opacity: 0 + transition: height 0.5s, opacity 0.5s + &_excerpt, + &_meta + transform-origin: bottom + &_meta + padding: 10px 1.25rem 1.25rem + color: var(--text) + position: relative + z-index: 2 + transition: margin-top 0.5s + background: var(--bg) + &.center_y + transform-origin: center + transition: transform 0.5s + display: flex + flex-direction: column + justify-content: center + @media screen and (min-width: 42rem) + left: -2rem + + &_thumb + display: grid + position: relative + z-index: 0 + overflow: hidden + height: 15rem + background-size: cover + background-position: 50% 50% + @media screen and (min-width: 35rem) + height: 22.5rem + + img + transition: transform 0.5s, opacity 0.5s + + &::after + content: '' + position: absolute + top: 0 + left: 0 + width: 100% + bottom: 0 + z-index: 1 + background: var(--bg) + opacity: 0 + transition: opacity 0.1s ease-out + + &_showcase &_thumb + height: 15rem + + &_showcase &_meta + padding-top: 1.5rem + + &:hover &_thumb + img + transform: scale(1.1) + + &::after + transition: opacity 0.1s ease-out + opacity: 0.5 + + &:hover &_excerpt:not(.visible) + height: 75px + opacity: 1 + + &:hover &_meta + &:not(.center_y) + margin-top: -75px + + @media screen and (min-width: 769px) + &.center_y + transform: translateX(-3rem) + + &:hover + box-shadow: 0 1.5rem 6rem rgba(0,0,0,0.17) + a + color: initial !important + + &_hidden + display: none \ No newline at end of file diff --git a/assets/sass/_chart.sass b/assets/sass/_chart.sass new file mode 100644 index 0000000..d376872 --- /dev/null +++ b/assets/sass/_chart.sass @@ -0,0 +1,38 @@ +@keyframes chartjs-render-animation + 0% + opacity: .99 + 100% + opacity: 1 + +.chartjs + &-render-monitor + animation: chartjs-render-animation 1ms + + &-size-monitor + &, &-expand, &-shrink + position: absolute + direction: ltr + left: 0 + top: 0 + right: 0 + bottom: 0 + overflow: hidden + pointer-events: none + visibility: hidden + z-index: -1 + + &-expand + > div + position: absolute + width: 1000000px + height: 1000000px + left: 0 + top: 0 + + &-shrink + > div + position: absolute + width: 200% + height: 200% + left: 0 + top: 0 diff --git a/assets/sass/_components.sass b/assets/sass/_components.sass new file mode 100644 index 0000000..6cf7fa6 --- /dev/null +++ b/assets/sass/_components.sass @@ -0,0 +1,374 @@ +.section + &_title + font-size: 1.25rem + &_link + font-size: 1rem + font-weight: 400 + +.sidebar + &-link + display: grid + padding: 0.2rem 0 + +.toc + border-left: 2px solid var(--theme) + padding: 0 1rem + height: 0 + overflow: hidden + filter: opacity(0.87) + &_item + font-size: 0.9rem + &_active + height: initial +.search + flex: 1 + display: flex + justify-content: flex-end + position: relative + &_field + padding: 0.5rem 1.5rem 0.5rem 2.5rem + border-radius: 1.5rem + width: 13.5rem + outline: none + border: 1px solid var(--search-border-color) + background: transparent + color: var(--text) + box-shadow: 0 1rem 4rem rgba(0,0,0,0.17) + font-size: 1rem + &:hover, &:focus + background: var(--search-bg) + &_label + width: 1rem + height: 1rem + position: absolute + left: 0.33rem + top: 0.25rem + opacity: 0.33 + svg + width: 100% + height: 100% + fill: var(--text) + &_result + padding: 0.5rem 1rem + display: block + &:not(.passive):hover + background-color: var(--theme) + color: var(--light) + &.passive + display: grid + &s + width: 13.5rem + background-color: var(--overlay) + border-radius: 0 0 0.25rem 0.25rem + box-shadow: 0 1rem 4rem rgba(0,0,0,0.17) + position: absolute + top: 125% + display: grid + overflow: hidden + z-index: 5 + &:empty + display: none + &_title + padding: 0.5rem 1rem 0.5rem 1rem + background: var(--theme) + color: var(--light) + font-size: 0.9rem + opacity: 0.87 + text-transform: uppercase + +.button + background-color: var(--theme) + color: var(--light) + border-radius: 0.25rem + display: inline-block + padding: 0.75rem 1.25rem + text-align: center + &:hover + opacity: 0.84 + & + & + background-color: var(--haze) + color: var(--dark) + &_grid + display: grid + max-width: 15rem + grid-gap: 1rem + grid-template-columns: repeat( auto-fit, minmax(12rem, 1fr) ) + @media screen and (min-width: 557px) + max-width: 25rem + +.video + overflow: hidden + padding-bottom: 56.25% + position: relative + height: 0 + margin: 1.5rem 0 + border-radius: 0.6rem + background-color: var(--bg) + box-shadow: 0 1rem 2rem rgba(0,0,0,0.17) + iframe + left: 0 + top: 0 + height: 100% + width: 100% + border: none + position: absolute + transform: scale(1.02) +.icon + width: 1.1rem + height: 1.1rem + display: inline-flex + justify-content: center + align-items: center + margin: 0 0.5rem + +.link + opacity: 0 + position: relative + &_owner:hover & + opacity: 1 + &_yank + opacity: 1 + &ed + position: absolute + right: -2.2rem + top: -2rem + background-color: var(--theme) + color: var(--light) + width: 7rem + padding: 0.25rem 0.5rem + font-size: 0.9rem + border-radius: 1rem + text-align: center + &::after + position: absolute + top: 1rem + content: "" + border-color: var(--theme) transparent + border-style: solid + border-width: 1rem 1rem 0 1rem + height: 0 + width: 0 + transform-origin: 50% 50% + transform: rotate(145deg) + right: 0.45rem + +.gallery + width: 100% + column-count: 3 + column-gap: 1rem + @media screen and (max-width: 667px) + column-count: 2 + &_item + background-color: transparent + margin: 0 0 1rem + &_image + margin: 0 auto + +.pager + display: flex + justify-content: space-between + align-items: center + padding-top: 2rem + margin: 2rem 0 + max-width: 100vw + overflow: hidden + svg + filter: opacity(0.75) + width: 1.25rem + height: 1rem + transform-origin: 50% 50% + + &_lean + justify-content: flex-end + + &_label + max-width: 100% + overflow: hidden + white-space: nowrap + text-overflow: ellipsis + + &_link + padding: 0.5rem 1rem + border-radius: 0.25rem + width: 12.5rem + max-width: 40vw + position: relative + display: flex + align-items: center + text-align: center + justify-content: center + &::before, &::after + background-image: var(--next-icon) + height: 0.8rem + width: 0.8rem + background-size: 100% + background-repeat: no-repeat + transform-origin: 50% 50% + + &_item + display: flex + flex-direction: column + flex: 1 + max-width: 48% + // filter: opacity(0.87) + &.prev + align-items: flex-start + // margin-right: 0.5rem + + &.next + align-items: flex-end + // margin-left: 0.5rem + &::after + content: "" + + &_item.prev &_link + &::before + content: "" + transform: rotate(180deg) + margin-right: 0.67rem + + &_item.next &_link + &::after + content: "" + margin-left: 0.67rem + + &_item.next &_link + grid-template-columns: 1fr 1.5rem + + &_meta + margin: 0.5rem 0 + +.color + &_mode + margin-left: 1rem + + &_choice + outline: none + border: none + -webkit-appearance: none + height: 1rem + position: relative + width: 1rem + border-radius: 1rem + cursor: pointer + z-index: 2 + right: 0 + filter: contrast(0.8) + + &::after + content: "" + top: 0.1rem + bottom: 0 + left: 0 + position: absolute + height: 1.3rem + background: var(--accent) + width: 1.3rem + border-radius: 0.4rem + z-index: 3 + background-image: var(--sun-icon) + background-size: 60% + background-repeat: no-repeat + background-position: center + + &_icon + height: 1rem + width: 1rem + margin: 0 + z-index: 4 + position: absolute + transform: translateY(-50%) + transition: transform 0.5s cubic-bezier(.19,1,.22,1) + right: 3.5rem + +.tip + padding: 1.5rem 1rem 1.5rem 1.5rem + margin: 1.5rem 0 + border-left: 0.2rem solid var(--theme) + position: relative + background: var(--accent) + blockquote + padding: 0 + margin: 0 + border: none + &::before + display: none + p + &:first-child, ~ p + padding-top: 0 + &:last-child + padding-bottom: 0 + &_warning + --theme: var(--inline-color) + &_warning::before + transform: rotate(180deg) + &::before + content: "" + position: absolute + left: -0.85rem + top: 1.5rem + z-index: 3 + padding: 0.75rem + transform-origin: 50% 50% + border-radius: 50% + background-color: var(--theme) + background-image: var(--info-icon) + background-size: 12% + background-position: 50% 50% + background-repeat: no-repeat + +.tabs + display: flex + flex-wrap: wrap + margin: 2rem 0 2rem 0 + position: relative + + &.tabs-left + justify-content: flex-start + + label.tab-label + margin-right: 0.5rem + + .tab-content + border-radius: 0px 6px 6px 6px + + &.tabs-right + justify-content: flex-end + + label.tab-label + margin-left: 0.5rem + + .tab-content + border-radius: 6px 6px 6px 6px + + input.tab-input + display: none + + label.tab-label + background-color: var(--accent) transparent + border-color: var(--theme) + border-radius: 6px 6px 0px 0px + border-style: solid + border-bottom-style: hidden + border-width: 2px + cursor: pointer + display: inline-block + order: 1 + padding: 0.3rem 0.6rem + position: relative + top: 2px + user-select: none + + input.tab-input:checked + label.tab-label + background-color: var(--accent) + border-color: var(--theme) + + .tab-content + background-color: var(--accent) + border-color: var(--theme) + border-style: solid + border-width: 2px + display: none + order: 2 + padding: 1rem + width: 100% diff --git a/assets/sass/_custom.sass b/assets/sass/_custom.sass new file mode 100644 index 0000000..2d22745 --- /dev/null +++ b/assets/sass/_custom.sass @@ -0,0 +1,4 @@ +// add customs styles and general overrides here +// due to the cascading nature of css, if you try to override theme css variables in this file, those changes will not apply. Instead, override css variables in the `override.sass` file +// we recommend not editing this file directly. Instead, create an `assets/sass/_custom.sass` file at the root level of your site. +// if you edit this file directly, you will have to resolve git conflicts when and if you decide to pull changes we make on the theme diff --git a/assets/sass/_fonts.sass b/assets/sass/_fonts.sass new file mode 100644 index 0000000..29d5f29 --- /dev/null +++ b/assets/sass/_fonts.sass @@ -0,0 +1,42 @@ +$font-path: "../fonts" +@font-face + font-family: 'Metropolis' + font-style: normal + font-weight: 400 + src: local('Metropolis Regular'), local('Metropolis-Regular'), url('#{$font-path}/Metropolis-Regular.woff2') format('woff2'), url('#{$font-path}/Metropolis-Regular.woff') format('woff') + font-display: swap + +@font-face + font-family: 'Metropolis' + font-style: normal + font-weight: 300 + src: local('Metropolis Light'), local('Metropolis-Light'), url('#{$font-path}/Metropolis-Light.woff2') format('woff2'), url('#{$font-path}/Metropolis-Light.woff') format('woff') + font-display: swap + +@font-face + font-family: 'Metropolis' + font-style: italic + font-weight: 300 + src: local('Metropolis Light Italic'), local('Metropolis-LightItalic'), url('#{$font-path}/Metropolis-LightItalic.woff2') format('woff2'), url('#{$font-path}/Metropolis-LightItalic.woff') format('woff') + font-display: swap + +@font-face + font-family: 'Metropolis' + font-style: normal + font-weight: 500 + src: local('Metropolis Medium'), local('Metropolis-Medium'), url('#{$font-path}/Metropolis-Medium.woff2') format('woff2'), url('#{$font-path}/Metropolis-Medium.woff') format('woff') + font-display: swap + +@font-face + font-family: 'Metropolis' + font-style: italic + font-weight: 500 + src: local('Metropolis Medium Italic'), local('Metropolis-MediumItalic'), url('#{$font-path}/Metropolis-MediumItalic.woff2') format('woff2'), url('#{$font-path}/Metropolis-MediumItalic.woff') format('woff') + font-display: swap + +@font-face + font-family: 'Cookie' + font-style: normal + font-weight: 400 + src: local('Cookie-Regular'), url('#{$font-path}/cookie-v10-latin-regular.woff2') format('woff2'), url('#{$font-path}/cookie-v10-latin-regular.woff') format('woff') + font-display: swap diff --git a/assets/sass/_mermaid.sass b/assets/sass/_mermaid.sass new file mode 100644 index 0000000..c175fa2 --- /dev/null +++ b/assets/sass/_mermaid.sass @@ -0,0 +1,7 @@ +html[data-mode="dark"] .mermaid + --theme: darkgoldenrod + background-color: transparent !important + margin-bottom: 2.5rem + svg + margin: 0 auto + display: block \ No newline at end of file diff --git a/assets/sass/_nav.sass b/assets/sass/_nav.sass new file mode 100644 index 0000000..ca2ef87 --- /dev/null +++ b/assets/sass/_nav.sass @@ -0,0 +1,71 @@ +.nav + display: grid + grid-gap: 1rem + padding: 0 1.5rem !important + align-items: center + background-color: var(--bg) + @media screen and (min-width: 992px) + grid-template-columns: 10rem 1fr + &_brand + position: relative + picture, img + max-width: 10rem + &_header + position: absolute + top: 0 + left: 0 + width: 100% + background-color: var(--bg) + z-index: 999999 + &_toggle + position: absolute + top: 0 + bottom: 0 + width: 3rem + display: flex + align-items: center + justify-content: flex-end + text-align: center + right: 0 + color: var(--text) + @media screen and (min-width: 992px) + display: none + &_body + display: flex + flex-direction: column + background: var(--accent) + position: fixed + left: 0 + top: 0 + bottom: 0 + height: 100vh + transition: transform 0.25s var(--ease) + transform: translateX(-101vw) + @media screen and (min-width: 992px) + transform: translateX(0) + position: relative + height: initial + justify-content: flex-end + background: transparent + flex-direction: row + &.show &_body + transform: translateX(0) + box-shadow: 0 1rem 4rem rgba(0,0,0,0.1) + background: var(--bg) + li:first-child + margin: 1.5rem 1rem 0.5rem 1rem + overflow-y: auto + // input + // background: var(--accent) + &-link + display: inline-flex + padding: 0.5rem 1rem + &-item + display: grid + align-items: center + .search + @media screen and (min-width: 992px) + margin-right: 1.5rem + &_repo + picture, img + max-width: 1.25rem diff --git a/assets/sass/_syntax.sass b/assets/sass/_syntax.sass new file mode 100644 index 0000000..cca8ba9 --- /dev/null +++ b/assets/sass/_syntax.sass @@ -0,0 +1,250 @@ +@keyframes pulse + 0% + opacity: 1 + 75% + opacity: 0.1 + 100% + opacity: 1 + +code + font-size: 15px + font-weight: 400 + overflow-y: hidden + display: block + font-family: 'Monaco', monospace + word-break: break-all + &.noClass + color: var(--inline-color) + display: inline + line-break: anywhere +.windows .highlight + overflow-x: hidden + &:hover + overflow-x: auto + +.highlight + display: grid + width: 100% + border-radius: 0 0.2rem 0.2rem 0 + overflow-x: auto + position: relative + &_wrap + display: grid + background: var(--code-bg) !important + border-radius: 0.5rem + position: relative + padding: 0 1rem + margin: 1.5rem auto 1rem auto + & & + margin: 0 + padding: 0 + & + & + margin-top: 2.25rem + &:hover > div + opacity: 1 + .lang + position: absolute + top: 0 + right: 0 + text-align: right + width: 7.5rem + padding: 0.5rem 1rem + font-style: italic + text-transform: uppercase + font-size: 67% + opacity: 0.5 + color: var(--text) + &:hover .lang + opacity: 0.1 + & & + margin: 0 + pre + color: var(--text) !important + border-radius: 4px + font-family: 'Monaco', monospace + padding-top: 1.5rem + padding-bottom: 2rem + + table + display: grid + max-width: 100% + margin-bottom: 0 + background: transparent + td, th + padding: 0 + + .lntd + width: 100% + border: none + &:first-child + &, pre + width: 2.5rem !important + padding-left: 0 + padding-right: 0 + color: rgba(255,255,255,0.5) + user-select: none + + pre + width: 100% + display: flex + min-width: 0 + align-items: center + flex-direction: column + +.err + color: #a61717 +.hl + width: 100% + background: var(--inline-color) +.ln, .lnt + margin-right: 0.75rem + padding: 0 + transition: opacity 0.3s var(--ease) + &, span + color: var(--text) + opacity: 0.5 + user-select: none + +.k, .kc, .kd, .kn, .kp, .kr, .kt, .nt + color: #6ab825 + font-weight: 500 + +.kn, .kp + font-weight: 400 + +.nb, .no, .nv + color: #24909d + +.nc, .nf, .nn + color: #447fcf + +.s, .sa, .sb, .sc, .dl, .sd, .s2, .se, .sh, .si, .sx, .sr, .s1, .ss + color: #ed9d13 + +.m, .mb, .mf, .mh, .mi, .il, .mo + color: #3677a9 + +.ow + color: #6ab825 + font-weight: 500 + +.c, .ch, .cm, .c1 + color: #999 + font-style: italic + +.cs + color: #e50808 + background-color: #520000 + font-weight: 500 + +.cp, .cpf + color: #cd2828 + font-weight: 500 + +.gd, .gr + color: #d22323 + +.ge + font-style: italic + +.gh, .gu, .nd, .na, .ne + color: #ffa500 + font-weight: 500 + +.gi + color: #589819 + +.go + color: #ccc + +.gp + color: #aaa + +.gs + font-weight: 500 + +.gt + color: #d22323 +.w + color: #666 + +.hljs + &-string + color: #6ab825 + &-attr + color: #ed9d13 + .p &-attr + color: var(--light) + +.pre + &_wrap + white-space: pre-wrap + white-space: -moz-pre-wrap + white-space: -pre-wrap + white-space: -o-pre-wrap + word-wrap: break-word + + &_nolines.ln + display: none + +// crayon-like widget styles +.panel + &_box + display: inline-flex + perspective: 300px + grid-gap: 1rem + transition: opacity 0.3s var(--easing) + background: var(--code-bg) + padding: 0.5rem 1.5rem + border-radius: 2rem + align-items: center + position: absolute + right: 0rem + top: -2.1rem + opacity: 0 + min-width: 0 + &_icon + display: inline-flex + align-items: center + justify-content: center + cursor: pointer + padding: 0.1rem + transform-origin: 50% 50% + margin: 0 + min-width: 0 + &.active + animation: pulse 0.1s linear + svg + fill: var(--text) + width: 1.5rem + height: 1.5rem + &_hide + // hide icon if not needed + display: none + &_from + position: absolute + color: var(--theme) + bottom: 0 + font-size: 1.5rem + font-weight: 500 + padding: 0.5rem 0 + cursor: pointer + letter-spacing: 0.1px + z-index: 19 + &_expanded &_from + display: none + +.shell + position: relative + // display: flex + // align-items: center + // gap: 0.5rem + &::before + content: "$" + position: relative + margin-right: 0.36rem + +.line + &-flex + display: flex + min-width: 0 diff --git a/assets/sass/_utils.sass b/assets/sass/_utils.sass new file mode 100644 index 0000000..f712c9b --- /dev/null +++ b/assets/sass/_utils.sass @@ -0,0 +1,105 @@ +.wrap + max-width: 1240px + @media screen and (min-width: 1640px) + max-width: 1600px + &, & + width: 100% + padding: 0 25px + margin: 0 auto + +@for $i from 1 through 8 + $size: $i * 1.5rem + $x-size: $size * 0.5 + .pt-#{$i} + padding-top: $size + + .pb-#{$i} + padding-bottom: $size + + .mt-#{$i} + margin-top: $size + + .mb-#{$i} + margin-bottom: $size + +%grid + display: grid + grid-template-columns: 1fr + +[class*='grid-'] + grid-gap: 2rem + +.grid-2, .grid-3, .grid-4, .grid-auto, .grid-reverse + @extend %grid + +@media screen and (min-width: 42rem) + .grid-auto + grid-template-columns: 2fr 5fr + + .grid-reverse + grid-template-columns: 3fr 1fr + + .grid-2 + grid-template-columns: repeat(2, 1fr) + + .grid-3 + grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)) + + .grid-4 + grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)) + +.active + color: var(--theme) + +.is + background: var(--theme) + color: var(--light) + +.toggle + svg + fill: var(--text) + display: inline-block + transform-origin: 50% 50% + transform: scale(1.2) + cursor: pointer + margin: 0 + +.scrollable + width: 100% + overflow-x: hidden + max-width: calc(100vw - 48px) + @media screen and (min-width: 768px) + max-width: 100% + &:hover + overflow-x: auto + +.chart + display: grid + grid-gap: 1.5rem + min-width: 0 + max-width: 98vw !important + max-height: 98vw !important + + +.link + display: inline-flex + align-items: center + width: 2.5rem + margin: 0 0.25rem 0 0 + padding: 0 0.25rem + opacity: 0 + transform: translate(-0.33rem, 0.33rem) + transition: opacity 0.3s cubic-bezier(0.39, 0.575, 0.565, 1) + svg, img + width: 1.5rem + height: 1.5rem + fill: var(--theme) + &_owner:hover & + opacity: 1 + +.copy + cursor: pointer + +.standardize-input + appearance: none + -webkit-appearance: none diff --git a/assets/sass/_variables.sass b/assets/sass/_variables.sass new file mode 100644 index 0000000..f064511 --- /dev/null +++ b/assets/sass/_variables.sass @@ -0,0 +1,56 @@ + +html + --color-mode: "light" + --light: #fff + --dark: rgb(28,28,30) + --haze: #f2f5f7 + --bubble: rgb(36,36,38) + --accent: var(--haze) + --bg: var(--light) + --code-bg: var(--accent) + --overlay: var(--light) + //--text: #111 + --text: #141010 + --font: 'Metropolis', sans-serif + --border-color: #eee + --inline-color: darkgoldenrod + --theme: rgb(52,199,89) + --ease: ease + --scroll-thumb: rgba(0,0,0,.06) + --search-border-color: transparent + --next-icon-path: url(../images/icons/double-arrow.svg) + --never-icon-path: url(../images/sitting.svg) + + @mixin darkmode + --color-mode: "dark" + --theme: rgb(48,209,88) + --bg: var(--dark) + --text: #eee + --text-light: #fff + --accent: var(--bubble) + --overlay: var(--bubble) + --border-color: transparent + --scroll-thumb: rgba(255,255,255,.06) + --search-bg: var(--accent) + --search-border-color: var(--accent) + * + box-shadow: none !important + + &[data-mode="dark"] + @include darkmode + .color + &_choice + &::after + background-image: var(--moon-icon) + + &[data-mode="auto"] + @media (prefers-color-scheme: dark) + @include darkmode + +%narrow + max-width: 750px + margin: 0 auto + +blockquote + + .highlight_wrap + margin-top: 2.25rem \ No newline at end of file diff --git a/assets/sass/main.sass b/assets/sass/main.sass new file mode 100644 index 0000000..8cf0463 --- /dev/null +++ b/assets/sass/main.sass @@ -0,0 +1,18 @@ +{{ $iconsPath := partialCached "functions/getIconPath" . }} +html + --info-icon: url('{{ absURL $iconsPath }}info.svg') + --sun-icon: url('{{ absURL $iconsPath }}sun.svg') + --moon-icon: url('{{ absURL $iconsPath }}moon.svg') + --next-icon: url('{{ absURL $iconsPath }}next.svg') +@import "variables" +@import "base" +@import "nav" +@import "components" +@import "mermaid" +@import "blog" +@import "utils" +@import "syntax" +@import "fonts" +@import "chart" +@import "custom" +@import "mermaid" diff --git a/dist/.gitkeep b/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/exampleSite/.github/workflows/agolia-update.yaml b/exampleSite/.github/workflows/agolia-update.yaml new file mode 100644 index 0000000..d644a04 --- /dev/null +++ b/exampleSite/.github/workflows/agolia-update.yaml @@ -0,0 +1,101 @@ +name: Update Algolia Search Index + +off: # change to `on:` to turn on + workflow_dispatch: + branches: + - production + push: + paths: + - content/**/* + - hugo.toml + +env: + # Name of the branch in your repository which will store your generated site. + SITE-BRANCH: master + +jobs: + build: + # In this phase, the code is pulled from main and the site rendered in Hugo. The built site is stored as an artifact for other stages. # deploy: + runs-on: ubuntu-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true # Fetch Hugo themes (true OR recursive) + fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod + + - name: Setup Hugo + uses: peaceiris/actions-hugo@v2 + with: + hugo-version: 'latest' + extended: true + + - name: Build + run: hugo -e "production" -d "dist" --minify + # If build succeeds, store the dist/ dir as an artifact to be used in subsequent phases. + - name: Upload output dist dir as artifact + uses: actions/upload-artifact@v1 + with: + name: dist + path: dist/ + publish: + # In the publish phase, the site is pushed up to a different branch which only stores the dist/ folder ("site" branch) and is also delta synchronized to the S3 bucket. CloudFront invalidation happens last. + runs-on: ubuntu-20.04 + needs: build + steps: + # Check out the site branch this time since we have to ultimately commit those changes there. + - name: Checkout site branch + uses: actions/checkout@v3 + with: + submodules: true + fetch-depth: 0 + ref: ${{ env.SITE-BRANCH }} + # Download the artifact containing the newly built site. This overwrites the dist/ dir from the check out above. + - name: Download artifact from build stage + uses: actions/download-artifact@v1 + with: + name: dist + # Add all the files/changes in dist/ that were pulled down from the build stage and then commit them. + # The final line sets a GitHub Action output value that can be read by other steps. + # This function cannot store mult-line values so newline chars must be stripped. + - name: Commit files + id: can_commit + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + cp dist/index.json index.json + git add -A index.json + commit_message=$(git commit -m "Build search index." -a | tr -d '\n' || true) + echo "commit_message=$commxit_message >> $GITHUB_OUTPUT" + + # Checks if previous stage had any valid commit. + - name: Nothing to commit + id: nothing_committed + if: contains(steps.can_commit.outputs.commit_message, 'nothing to commit') + run: echo "Saw that no changes were made to Hugo site." + # Push those changes back to the site branch. + - name: Push to site branch + if: steps.nothing_committed.conclusion == 'skipped' + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.SITE-BRANCH }} + index: + runs-on: ubuntu-latest + needs: publish + name: Upload Algolia Index + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: wangchucheng/algolia-uploader@master + with: + # Such as `Z0U0ACGBN8` + app_id: ${{ secrets.AGOLIA_INDEX_ID }} + # Go to https://github.com/dimi365/website/settings/secrets/actions and set an AGOLIA_ADMIN_KEY secret key + admin_key: ${{ secrets.AGOLIA_ADMIN_KEY }} + # The algolia search index name. + index_name: compose # edit appropriately + # The index file path relative to repo root. no leading forward slash + index_file_path: index.json \ No newline at end of file diff --git a/exampleSite/.github/workflows/aws-deploy.yaml b/exampleSite/.github/workflows/aws-deploy.yaml new file mode 100644 index 0000000..af9752b --- /dev/null +++ b/exampleSite/.github/workflows/aws-deploy.yaml @@ -0,0 +1,118 @@ +# PREREQUISITES: +# The following secrets must be stored in your repository where this Action runs: +# AWS_ACCESS_KEY_ID +# AWS_CLOUDFRONT_DISTRO_ID +# AWS_S3_BUCKET_NAME +# AWS_SECRET_ACCESS_KEY + +name: AWS DEPLOY CI +off: # change to `on:` to turn on + workflow_dispatch: + branches: + - main + push: + paths: + - content/**/* + - hugo.toml + # pull_request: + # branches: + # - production +env: + # Default AWS region where S3 pushes and CloudFront invalidations will occur. + AWS-DEFAULT-REGION: us-east-2 + # Name of the branch in your repository which will store your generated site. + SITE-BRANCH: site + +jobs: + build: + # In this phase, the code is pulled from main and the site rendered in Hugo. The built site is stored as an artifact for other stages. # deploy: + runs-on: ubuntu-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true # Fetch Hugo themes (true OR recursive) + fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod + + - name: Setup Hugo + uses: peaceiris/actions-hugo@v2 + with: + hugo-version: 'latest' + extended: true + + - name: Build + run: hugo -e "production" -d "dist" --minify + # If build succeeds, store the dist/ dir as an artifact to be used in subsequent phases. + - name: Upload output public dir as artifact + uses: actions/upload-artifact@v1 + with: + name: dist + path: dist/ + publish: + # In the publish phase, the site is pushed up to a different branch which only stores the dist/ folder ("site" branch) and is also delta synchronized to the S3 bucket. CloudFront invalidation happens last. + runs-on: ubuntu-20.04 + needs: build + steps: + # Check out the site branch this time since we have to ultimately commit those changes there. + - name: Checkout site branch + uses: actions/checkout@v3 + with: + submodules: true + fetch-depth: 0 + ref: ${{ env.SITE-BRANCH }} + # Download the artifact containing the newly built site. This overwrites the dist/ dir from the check out above. + - name: Download artifact from build stage + uses: actions/download-artifact@v1 + with: + name: public + # Add all the files/changes in dist/ that were pulled down from the build stage and then commit them. + # The final line sets a GitHub Action output value that can be read by other steps. + # This function cannot store mult-line values so newline chars must be stripped. + - name: Commit files + id: can_commit + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -A dist/ + commit_message=$(git commit -m "Publish generated Hugo site." -a | tr -d '\n' || true) + echo "commit_message=$commit_message >> $GITHUB_OUTPUT" + # Checks if previous stage had any valid commit. + - name: Nothing to commit + id: nothing_committed + if: contains(steps.can_commit.outputs.commit_message, 'nothing to commit') + run: echo "Saw that no changes were made to Hugo site." + # Push those changes back to the site branch. + - name: Push to site branch + if: steps.nothing_committed.conclusion == 'skipped' + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.SITE-BRANCH }} + # Store the AWS credentials on the runner. + - name: Configure AWS credentials + if: steps.nothing_committed.conclusion == 'skipped' + uses: aws-actions/configure-aws-credentials@v1-node16 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS-DEFAULT-REGION }} + - name: Delta sync site to S3 with aws cli + if: steps.nothing_committed.conclusion == 'skipped' + run: aws s3 sync --size-only --delete --exclude "/authors/*/page/*" --cache-control max-age=2592000 dist/ s3://${{ secrets.AWS_S3_BUCKET_NAME }} + # Use s5cmd to perform only a delta sync to the destination S3 bucket. This minimizes transfer traffic since it only uploads changed files. + # - name: Delta sync site to S3 bucket + # if: steps.nothing_committed.conclusion == 'skipped' + # run: | + # curl -sLO https://github.com/peak/s5cmd/releases/download/v1.0.0/s5cmd_1.0.0_Linux-64bit.tar.gz + # tar -xzf s5cmd_1.0.0_Linux-64bit.tar.gz + # chmod +x s5cmd + # sudo mv s5cmd /usr/local/bin/ + # echo "****Showing working dir and listing files.****" + # pwd && ls -lah + # echo "****Running delta sync against S3.****" + # s5cmd cp -s -n -u dist/ s3://${{ secrets.AWS_S3_BUCKET_NAME }} + # Use the aws cli tool to perform a glob invalidation of the entire site against CloudFront. + - name: Invalidate cache on CloudFront + if: steps.nothing_committed.conclusion == 'skipped' + run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRO_ID }} --paths "/*" \ No newline at end of file diff --git a/exampleSite/LICENSE b/exampleSite/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/exampleSite/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/exampleSite/README.md b/exampleSite/README.md new file mode 100644 index 0000000..5a246e9 --- /dev/null +++ b/exampleSite/README.md @@ -0,0 +1,3 @@ +## Guide + +This guide covers the necessary bits. As the project evolves, it will only become more comprehensive diff --git a/exampleSite/config/.gitkeep b/exampleSite/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/exampleSite/config/_default/languages.toml b/exampleSite/config/_default/languages.toml new file mode 100644 index 0000000..b00ad44 --- /dev/null +++ b/exampleSite/config/_default/languages.toml @@ -0,0 +1,6 @@ +[en] + LanguageName = "English" + weight = 2 +# [tr] +# LanguageName = "Turkish" +# weight = 1 diff --git a/exampleSite/config/_default/markup.toml b/exampleSite/config/_default/markup.toml new file mode 100644 index 0000000..adc933a --- /dev/null +++ b/exampleSite/config/_default/markup.toml @@ -0,0 +1,19 @@ +[goldmark] + [goldmark.renderer] + unsafe = true + [goldmark.extensions] + typographer = false +[highlight] + codeFences = true + guessSyntax = false + hl_Lines = "" + lineNoStart = 1 + lineNos = true + lineNumbersInTable = false + noClasses = false + style = "monokai" + tabWidth = 2 +[tableOfContents] + endLevel = 4 + ordered = false + startLevel = 2 \ No newline at end of file diff --git a/exampleSite/config/_default/menus/menu.en.toml b/exampleSite/config/_default/menus/menu.en.toml new file mode 100644 index 0000000..b7a2b37 --- /dev/null +++ b/exampleSite/config/_default/menus/menu.en.toml @@ -0,0 +1,25 @@ +# menu items +[[main]] + name = "Blog" + weight = 5 + url = "blog/" + +[[main]] + name = "Docs" + weight = 2 + url = "docs/" + +[[main]] + name = "Tutorials" + weight = 2 + url = "tutorials/" + +[[main]] + name = "Example" + weight = 3 + url = "https://docs.neuralvibes.com" + +# [[main]] +# name = "Blog" +# weight = 4 +# url = "blog/" \ No newline at end of file diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml new file mode 100644 index 0000000..df27a32 --- /dev/null +++ b/exampleSite/config/_default/params.toml @@ -0,0 +1,55 @@ +# use the setting below to set multiple docs directories. +# docSections = ["docs", "tutorials"] + +uniqueHomePage = true # change to false to add sidebar to homepage + +blogDir = "blog" # can be posts, blog e.t.c + +repo = "https://github.com/onweru/compose" + +time_format_blog = "Monday, January 02, 2006" +time_format_default = "January 2, 2006" +enableDarkMode = false # set to false to disable darkmode by default # user will still have the option to use dark mode +defaultLightingMode = "auto" # other possible values: "dark", "light" + +# sets the maximum number of lines per codeblock. The codeblock will however be scrollable and expandable. +codeMaxLines = 10 + +# show/hide line numbers by default. Switch to `true` if you'd rather have them on. +showLineNumbers = false + +# By default the template will look for icons under the icons directory. In some situations you might wanna change that. edit the line below +# iconsPath = 'icons/' + +otherSearchableFields = ["Tags", "Categories", "CustomField"] # As they appear in frontmatter + +# Defaults to true if not set +# Enable copyRight Footer Stamp. Takes in attribution +enableCopyright = false + +# search +[search] +on = true +global = false # turn to `true` to enable global search +[search.algolia] +enable = false # if false search will default to fusejs +id = "Q40WQQX84U" # Application ID +index = "compose" # Index name +key = "da87401a458102ec6bbd6cc5e5cf8d95" # Search-Only API Key + +# Site logo +[logo] + lightMode = "images/compose.svg" + darkMode = "images/compose-light.svg" + +[source] + name = "GitHub" + iconLight = "images/GitHubMarkLight.svg" + iconDark = "images/GitHubMarkDark.svg" + url = "https://github.com/onweru/compose/" + +# optional +# attribution. Feel free to delete this +[author] + name = "Weru" + url = "https://neuralvibes.com/author/" diff --git a/exampleSite/content/_index.md b/exampleSite/content/_index.md new file mode 100644 index 0000000..ba8b366 --- /dev/null +++ b/exampleSite/content/_index.md @@ -0,0 +1,33 @@ ++++ +title = "Compose" +[data] +baseChartOn = 3 +colors = ["#627c62", "#11819b", "#ef7f1a", "#4e1154"] +columnTitles = ["Section", "Status", "Author"] +fileLink = "content/projects.csv" +title = "Projects" ++++ + +{{< block "grid-2" >}} +{{< column >}} + +# Compose your Docs with **Ease**. + +Compose is a lean `Hugo` documentation theme, inspired by [forestry.io](https://forestry.io/docs/welcome/). + +{{< tip "warning" >}} +Feel free to open a [PR](https://github.com/onweru/compose/pulls), raise an [issue](https://github.com/onweru/compose/issues/new/choose "Open a Github Issue")(s) or request new feature(s). {{< /tip >}} + +{{< tip >}} +You can generate diagrams, flowcharts, and piecharts from text in a similar manner as markdown using [mermaid](./docs/compose/mermaid/). + +Or, [generate graphs, charts](docs/compose/graphs-charts-tables/#show-a-pie-doughnut--bar-chart-at-once) and tables from a csv, ~~or a json~~ file. +{{< /tip >}} + +{{< button "docs/compose/" "Read the Docs" >}}{{< button "https://github.com/onweru/compose" "Download Theme" >}} +{{< /column >}} + +{{< column >}} +![diy](/images/scribble.jpg) +{{< /column >}} +{{< /block >}} diff --git a/exampleSite/content/blog/_index.md b/exampleSite/content/blog/_index.md new file mode 100644 index 0000000..9c952e2 --- /dev/null +++ b/exampleSite/content/blog/_index.md @@ -0,0 +1,3 @@ ++++ +title = "Blog" ++++ \ No newline at end of file diff --git a/exampleSite/content/blog/creating-a-new-theme.md b/exampleSite/content/blog/creating-a-new-theme.md new file mode 100644 index 0000000..932c131 --- /dev/null +++ b/exampleSite/content/blog/creating-a-new-theme.md @@ -0,0 +1,1097 @@ ++++ +author = "Michael Henderson" +date = 2014-09-28 +title = "Creating a New Theme" +image = "/images/boy.jpg" ++++ + +## Introduction + +This tutorial will show you how to create a simple theme in Hugo. I assume that you are familiar with HTML, the bash command line, and that you are comfortable using Markdown to format content. I'll explain how Hugo uses templates and how you can organize your templates to create a theme. I won't cover using CSS to style your theme. + +{{< youtube "https://www.youtube.com/watch?v=aOC8E8z_ifw" >}} + +We'll start with creating a new site with a very basic template. Then we'll add in a few pages and posts. With small variations on that, you will be able to create many different types of web sites. + +In this tutorial, commands that you enter will start with the "$" prompt. The output will follow. Lines that start with "#" are comments that I've added to explain a point. When I show updates to a file, the ":wq" on the last line means to save the file. + +Here's an example: + +```bash +## this is a comment +$ echo this is a command +this is a command + +## edit the file +$ vi foo.md ++++ +date = "2014-09-28" +title = "creating a new theme" ++++ + +bah and humbug +:wq + +## show it +$ cat foo.md ++++ +date = "2014-09-28" +title = "creating a new theme" ++++ + +bah and humbug +$ +``` + +## Some Definitions + +There are a few concepts that you need to understand before creating a theme. + +### Skins + +Skins are the files responsible for the look and feel of your site. It’s the CSS that controls colors and fonts, it’s the Javascript that determines actions and reactions. It’s also the rules that Hugo uses to transform your content into the HTML that the site will serve to visitors. + +You have two ways to create a skin. The simplest way is to create it in the `layouts/` directory. If you do, then you don’t have to worry about configuring Hugo to recognize it. The first place that Hugo will look for rules and files is in the `layouts/` directory so it will always find the skin. + +Your second choice is to create it in a sub-directory of the `themes/` directory. If you do, then you must always tell Hugo where to search for the skin. It’s extra work, though, so why bother with it? + +The difference between creating a skin in `layouts/` and creating it in `themes/` is very subtle. A skin in `layouts/` can’t be customized without updating the templates and static files that it is built from. A skin created in `themes/`, on the other hand, can be and that makes it easier for other people to use it. + +The rest of this tutorial will call a skin created in the `themes/` directory a theme. + +Note that you can use this tutorial to create a skin in the `layouts/` directory if you wish to. The main difference will be that you won’t need to update the site’s configuration file to use a theme. + +### The Home Page + +The home page, or landing page, is the first page that many visitors to a site see. It is the index.html file in the root directory of the web site. Since Hugo writes files to the public/ directory, our home page is public/index.html. + +### Site Configuration File + +When Hugo runs, it looks for a configuration file that contains settings that override default values for the entire site. The file can use TOML, YAML, or JSON. I prefer to use TOML for my configuration files. If you prefer to use JSON or YAML, you’ll need to translate my examples. You’ll also need to change the name of the file since Hugo uses the extension to determine how to process it. + +Hugo translates Markdown files into HTML. By default, Hugo expects to find Markdown files in your `content/` directory and template files in your `themes/` directory. It will create HTML files in your `public/` directory. You can change this by specifying alternate locations in the configuration file. + +### Content + +Content is stored in text files that contain two sections. The first section is the “front matter,” which is the meta-information on the content. The second section contains Markdown that will be converted to HTML. + +#### Front Matter + +The front matter is information about the content. Like the configuration file, it can be written in TOML, YAML, or JSON. Unlike the configuration file, Hugo doesn’t use the file’s extension to know the format. It looks for markers to signal the type. TOML is surrounded by “`+++`”, YAML by “`---`”, and JSON is enclosed in curly braces. I prefer to use TOML, so you’ll need to translate my examples if you prefer YAML or JSON. + +The information in the front matter is passed into the template before the content is rendere into HTML. + +#### Markdown + +Content is written in Markdown which makes it easier to create the content. Hugo runs the content through a Markdown engine to create the HTML which will be written to the output file. + +### Template Files + +Hugo uses template files to render content into HTML. Template files are a bridge between the content and presentation. Rules in the template define what content is published, where it's published to, and how it will rendered to the HTML file. The template guides the presentation by specifying the style to use. + +There are three types of templates: single, list, and partial. Each type takes a bit of content as input and transforms it based on the commands in the template. + +Hugo uses its knowledge of the content to find the template file used to render the content. If it can’t find a template that is an exact match for the content, it will shift up a level and search from there. It will continue to do so until it finds a matching template or runs out of templates to try. If it can’t find a template, it will use the default template for the site. + +Please note that you can use the front matter to influence Hugo’s choice of templates. + +#### Single Template + +A single template is used to render a single piece of content. For example, an article or post would be a single piece of content and use a single template. + +#### List Template + +A list template renders a group of related content. That could be a summary of recent postings or all articles in a category. List templates can contain multiple groups. + +The homepage template is a special type of list template. Hugo assumes that the home page of your site will act as the portal for the rest of the content in the site. + +#### Partial Template + +A partial template is a template that can be included in other templates. Partial templates must be called using the “partial” template command. They are very handy for rolling up common behavior. For example, your site may have a banner that all pages use. Instead of copying the text of the banner into every single and list template, you could create a partial with the banner in it. That way if you decide to change the banner, you only have to change the partial template. + +## Create a New Site + +Let's use Hugo to create a new web site. I'm a Mac user, so I'll create mine in my home directory, in the Sites folder. If you're using Linux, you might have to create the folder first. + +The "new site" command will create a skeleton of a site. It will give you the basic directory structure and a useable configuration file. + +```shell +$ hugo new site ~/Sites/zafta +$ cd ~/Sites/zafta +$ ls -l +total 8 +drwxr-xr-x 7 quoha staff 238 Sep 29 16:49 . +drwxr-xr-x 3 quoha staff 102 Sep 29 16:49 .. +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes +-rw-r--r-- 1 quoha staff 82 Sep 29 16:49 hugo.toml +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static +$ +``` + +Take a look in the content/ directory to confirm that it is empty. + +The other directories (archetypes/, layouts/, and static/) are used when customizing a theme. That's a topic for a different tutorial, so please ignore them for now. + +### Generate the HTML For the New Site + +Running the `hugo` command with no options will read all the available content and generate the HTML files. It will also copy all static files (that's everything that's not content). Since we have an empty site, it won't do much, but it will do it very quickly. + +```shell +$ hugo --verbose +INFO: 2014/09/29 Using config file: hugo.toml +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ +WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] +WARN: 2014/09/29 Unable to locate layout: [404.html] +0 draft content +0 future content +0 pages created +0 tags created +0 categories created +in 2 ms +$ +``` + +The "`--verbose`" flag gives extra information that will be helpful when we build the template. Every line of the output that starts with "INFO:" or "WARN:" is present because we used that flag. The lines that start with "WARN:" are warning messages. We'll go over them later. + +We can verify that the command worked by looking at the directory again. + +```shell +$ ls -l +total 8 +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes +-rw-r--r-- 1 quoha staff 82 Sep 29 16:49 hugo.toml +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts +drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static +$ +``` + +See that new public/ directory? Hugo placed all generated content there. When you're ready to publish your web site, that's the place to start. For now, though, let's just confirm that we have what we'd expect from a site with no content. + +```shell +$ ls -l public +total 16 +-rw-r--r-- 1 quoha staff 416 Sep 29 17:02 index.xml +-rw-r--r-- 1 quoha staff 262 Sep 29 17:02 sitemap.xml +$ +``` + +Hugo created two XML files, which is standard, but there are no HTML files. + +### Test the New Site + +Verify that you can run the built-in web server. It will dramatically shorten your development cycle if you do. Start it by running the "server" command. If it is successful, you will see output similar to the following: + +```shell +$ hugo server --verbose +INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ +WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] +WARN: 2014/09/29 Unable to locate layout: [404.html] +0 draft content +0 future content +0 pages created +0 tags created +0 categories created +in 2 ms +Serving pages from /Users/quoha/Sites/zafta/public +Web Server is available at http://localhost:1313 +Press Ctrl+C to stop +``` + +Connect to the listed URL (it's on the line that starts with "Web Server"). If everything is working correctly, you should get a page that shows the following: + + index.xml + sitemap.xml + +That's a listing of your public/ directory. Hugo didn't create a home page because our site has no content. When there's no index.html file in a directory, the server lists the files in the directory, which is what you should see in your browser. + +Let’s go back and look at those warnings again. + + WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] + WARN: 2014/09/29 Unable to locate layout: [404.html] + +That second warning is easier to explain. We haven’t created a template to be used to generate “page not found errors.” The 404 message is a topic for a separate tutorial. + +Now for the first warning. It is for the home page. You can tell because the first layout that it looked for was “index.html.” That’s only used by the home page. + +I like that the verbose flag causes Hugo to list the files that it's searching for. For the home page, they are index.html, _default/list.html, and _default/single.html. There are some rules that we'll cover later that explain the names and paths. For now, just remember that Hugo couldn't find a template for the home page and it told you so. + +At this point, you've got a working installation and site that we can build upon. All that’s left is to add some content and a theme to display it. + +## Create a New Theme + +Hugo doesn't ship with a default theme. There are a few available (I counted a dozen when I first installed Hugo) and Hugo comes with a command to create new themes. + +We're going to create a new theme called "zafta." Since the goal of this tutorial is to show you how to fill out the files to pull in your content, the theme will not contain any CSS. In other words, ugly but functional. + +All themes have opinions on content and layout. For example, Zafta uses "post" over "blog". Strong opinions make for simpler templates but differing opinions make it tougher to use themes. When you build a theme, consider using the terms that other themes do. + +### Create a Skeleton + +Use the hugo "new" command to create the skeleton of a theme. This creates the directory structure and places empty files for you to fill out. + +```shell + $ hugo new theme zafta + +$ ls -l +total 8 +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes +-rw-r--r-- 1 quoha staff 82 Sep 29 16:49 hugo.toml +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts +drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public +drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static +drwxr-xr-x 3 quoha staff 102 Sep 29 17:31 themes + +$ find themes -type f | xargs ls -l +-rw-r--r-- 1 quoha staff 1081 Sep 29 17:31 themes/zafta/LICENSE.md +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/archetypes/default.md +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/single.html +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/index.html +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/footer.html +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/header.html +-rw-r--r-- 1 quoha staff 93 Sep 29 17:31 themes/zafta/theme.toml +$ +``` + +The skeleton includes templates (the files ending in .html), license file, a description of your theme (the theme.toml file), and an empty archetype. + +Please take a minute to fill out the theme.toml and LICENSE.md files. They're optional, but if you're going to be distributing your theme, it tells the world who to praise (or blame). It's also nice to declare the license so that people will know how they can use the theme. + + $ vi themes/zafta/theme.toml + author = "michael d henderson" + description = "a minimal working template" + license = "MIT" + name = "zafta" + source_repo = "" + tags = ["tags", "categories"] + :wq + + ## also edit themes/zafta/LICENSE.md and change + ## the bit that says "YOUR_NAME_HERE" + +Note that the the skeleton's template files are empty. Don't worry, we'll be changing that shortly. + + $ find themes/zafta -name '*.html' | xargs ls -l + -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html + -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/single.html + -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/index.html + -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/footer.html + -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/header.html + $ + +### Update the Configuration File to Use the Theme + +Now that we've got a theme to work with, it's a good idea to add the theme name to the configuration file. This is optional, because you can always add "-t zafta" on all your commands. I like to put it the configuration file because I like shorter command lines. If you don't put it in the configuration file or specify it on the command line, you won't use the template that you're expecting to. + +Edit the file to add the theme, add a title for the site, and specify that all of our content will use the TOML format. + + $ vi hugo.toml + theme = "zafta" + baseurl = "" + languageCode = "en-us" + title = "zafta - totally refreshing" + MetaDataFormat = "toml" + :wq + + $ + +### Generate the Site + +Now that we have an empty theme, let's generate the site again. + +```shell +$ hugo --verbose +INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ +WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] +0 draft content +0 future content +0 pages created +0 tags created +0 categories created +in 2 ms +$ +``` + +Did you notice that the output is different? The warning message for the home page has disappeared and we have an additional information line saying that Hugo is syncing from the theme's directory. + +Let's check the public/ directory to see what Hugo's created. + +```shell +$ ls -l public +total 16 +drwxr-xr-x 2 quoha staff 68 Sep 29 17:56 css +-rw-r--r-- 1 quoha staff 0 Sep 29 17:56 index.html +-rw-r--r-- 1 quoha staff 407 Sep 29 17:56 index.xml +drwxr-xr-x 2 quoha staff 68 Sep 29 17:56 js +-rw-r--r-- 1 quoha staff 243 Sep 29 17:56 sitemap.xml +$ +``` + +Notice four things: + +1. Hugo created a home page. This is the file public/index.html. +2. Hugo created a css/ directory. +3. Hugo created a js/ directory. +4. Hugo claimed that it created 0 pages. It created a file and copied over static files, but didn't create any pages. That's because it considers a "page" to be a file created directly from a content file. It doesn't count things like the index.html files that it creates automatically. + +#### The Home Page + +Hugo supports many different types of templates. The home page is special because it gets its own type of template and its own template file. The file, layouts/index.html, is used to generate the HTML for the home page. The Hugo documentation says that this is the only required template, but that depends. Hugo's warning message shows that it looks for three different templates: + + WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] + +If it can't find any of these, it completely skips creating the home page. We noticed that when we built the site without having a theme installed. + +When Hugo created our theme, it created an empty home page template. Now, when we build the site, Hugo finds the template and uses it to generate the HTML for the home page. Since the template file is empty, the HTML file is empty, too. If the template had any rules in it, then Hugo would have used them to generate the home page. + +```shell +$ find . -name index.html | xargs ls -l +-rw-r--r-- 1 quoha staff 0 Sep 29 20:21 ./public/index.html +-rw-r--r-- 1 quoha staff 0 Sep 29 17:31 ./themes/zafta/layouts/index.html +$ +``` + +#### The Magic of Static + +Hugo does two things when generating the site. It uses templates to transform content into HTML and it copies static files into the site. Unlike content, static files are not transformed. They are copied exactly as they are. + +Hugo assumes that your site will use both CSS and JavaScript, so it creates directories in your theme to hold them. Remember opinions? Well, Hugo's opinion is that you'll store your CSS in a directory named css/ and your JavaScript in a directory named js/. If you don't like that, you can change the directory names in your theme directory or even delete them completely. Hugo's nice enough to offer its opinion, then behave nicely if you disagree. + +```shell +$ find themes/zafta -type d | xargs ls -ld +drwxr-xr-x 7 quoha staff 238 Sep 29 17:38 themes/zafta +drwxr-xr-x 3 quoha staff 102 Sep 29 17:31 themes/zafta/archetypes +drwxr-xr-x 5 quoha staff 170 Sep 29 17:31 themes/zafta/layouts +drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/layouts/_default +drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/layouts/partials +drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/static +drwxr-xr-x 2 quoha staff 68 Sep 29 17:31 themes/zafta/static/css +drwxr-xr-x 2 quoha staff 68 Sep 29 17:31 themes/zafta/static/js +$ +``` + +## The Theme Development Cycle + +When you're working on a theme, you will make changes in the theme's directory, rebuild the site, and check your changes in the browser. Hugo makes this very easy: + +1. Purge the public/ directory. +2. Run the built in web server in watch mode. +3. Open your site in a browser. +4. Update the theme. +5. Glance at your browser window to see changes. +6. Return to step 4. + +I’ll throw in one more opinion: never work on a theme on a live site. Always work on a copy of your site. Make changes to your theme, test them, then copy them up to your site. For added safety, use a tool like Git to keep a revision history of your content and your theme. Believe me when I say that it is too easy to lose both your mind and your changes. + +Check the main Hugo site for information on using Git with Hugo. + +### Purge the public/ Directory + +When generating the site, Hugo will create new files and update existing ones in the `public/` directory. It will not delete files that are no longer used. For example, files that were created in the wrong directory or with the wrong title will remain. If you leave them, you might get confused by them later. I recommend cleaning out your site prior to generating it. + +Note: If you're building on an SSD, you should ignore this. Churning on a SSD can be costly. + +### Hugo's Watch Option + +Hugo's "`--watch`" option will monitor the content/ and your theme directories for changes and rebuild the site automatically. + +### Live Reload + +Hugo's built in web server supports live reload. As pages are saved on the server, the browser is told to refresh the page. Usually, this happens faster than you can say, "Wow, that's totally amazing." + +### Development Commands + +Use the following commands as the basis for your workflow. + +```s +## purge old files. hugo will recreate the public directory. +## +$ rm -rf public +## +## run hugo in watch mode +## +$ hugo server --watch --verbose +``` + +Here's sample output showing Hugo detecting a change to the template for the home page. Once generated, the web browser automatically reloaded the page. I've said this before, it's amazing. + + $ rm -rf public + $ hugo server --watch --verbose + INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ + WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] + 0 draft content + 0 future content + 0 pages created + 0 tags created + 0 categories created + in 2 ms + Watching for changes in /Users/quoha/Sites/zafta/content + Serving pages from /Users/quoha/Sites/zafta/public + Web Server is available at http://localhost:1313 + Press Ctrl+C to stop + INFO: 2014/09/29 File System Event: ["/Users/quoha/Sites/zafta/themes/zafta/layouts/index.html": MODIFY|ATTRIB] + Change detected, rebuilding site + + WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] + 0 draft content + 0 future content + 0 pages created + 0 tags created + 0 categories created + in 1 ms + +## Update the Home Page Template + +The home page is one of a few special pages that Hugo creates automatically. As mentioned earlier, it looks for one of three files in the theme's layout/ directory: + +1. index.html +2. _default/list.html +3. _default/single.html + +We could update one of the default templates, but a good design decision is to update the most specific template available. That's not a hard and fast rule (in fact, we'll break it a few times in this tutorial), but it is a good generalization. + +### Make a Static Home Page + +Right now, that page is empty because we don't have any content and we don't have any logic in the template. Let's change that by adding some text to the template. + +```html + + + + +

hugo says hello!

+ + +``` + +Build the web site and then verify the results. + +```bash +$ hugo --verbose +INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ +WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] +0 draft content +0 future content +0 pages created +0 tags created +0 categories created +in 2 ms + +$ find public -type f -name '*.html' | xargs ls -l +-rw-r--r-- 1 quoha staff 78 Sep 29 21:26 public/index.html + +$ cat public/index.html + + + +

hugo says hello!

+ +``` + +#### Live Reload + +Note: If you're running the server with the `--watch` option, you'll see different content in the file: + +```html + + + +

hugo says hello!

+ + +``` +When you use `--watch`, the Live Reload script is added by Hugo. Look for live reload in the documentation to see what it does and how to disable it. + +### Build a "Dynamic" Home Page + +"Dynamic home page?" Hugo's a static web site generator, so this seems an odd thing to say. I mean let's have the home page automatically reflect the content in the site every time Hugo builds it. We'll use iteration in the template to do that. + +#### Create New Posts + +Now that we have the home page generating static content, let's add some content to the site. We'll display these posts as a list on the home page and on their own page, too. + +Hugo has a command to generate a skeleton post, just like it does for sites and themes. + +```bash +$ hugo --verbose new post/first.md +INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml +INFO: 2014/09/29 attempting to create post/first.md of post +INFO: 2014/09/29 curpath: /Users/quoha/Sites/zafta/themes/zafta/archetypes/default.md +ERROR: 2014/09/29 Unable to Cast to map[string]interface{} +``` + +That wasn't very nice, was it? + +The "new" command uses an archetype to create the post file. Hugo created an empty default archetype file, but that causes an error when there's a theme. For me, the workaround was to create an archetypes file specifically for the post type. + +```bash + $ vi themes/zafta/archetypes/post.md + +++ + Description = "" + Tags = [] + Categories = [] + +++ + :wq + + $ find themes/zafta/archetypes -type f | xargs ls -l + -rw-r--r-- 1 quoha staff 0 Sep 29 21:53 themes/zafta/archetypes/default.md + -rw-r--r-- 1 quoha staff 51 Sep 29 21:54 themes/zafta/archetypes/post.md + + $ hugo --verbose new post/first.md + INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml + INFO: 2014/09/29 attempting to create post/first.md of post + INFO: 2014/09/29 curpath: /Users/quoha/Sites/zafta/themes/zafta/archetypes/post.md + INFO: 2014/09/29 creating /Users/quoha/Sites/zafta/content/post/first.md + /Users/quoha/Sites/zafta/content/post/first.md created + + $ hugo --verbose new post/second.md + INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml + INFO: 2014/09/29 attempting to create post/second.md of post + INFO: 2014/09/29 curpath: /Users/quoha/Sites/zafta/themes/zafta/archetypes/post.md + INFO: 2014/09/29 creating /Users/quoha/Sites/zafta/content/post/second.md + /Users/quoha/Sites/zafta/content/post/second.md created + + $ ls -l content/post + total 16 + -rw-r--r-- 1 quoha staff 104 Sep 29 21:54 first.md + -rw-r--r-- 1 quoha staff 105 Sep 29 21:57 second.md + + $ cat content/post/first.md + +++ + Categories = [] + Description = "" + Tags = [] + date = "2014-09-29T21:54:53-05:00" + title = "first" + + +++ + my first post + + $ cat content/post/second.md + +++ + Categories = [] + Description = "" + Tags = [] + date = "2014-09-29T21:57:09-05:00" + title = "second" + + +++ + my second post + + $ +``` + +Build the web site and then verify the results. + +```bash +$ rm -rf public +$ hugo --verbose +INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ +INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ +INFO: 2014/09/29 found taxonomies: map[string]string{"category":"categories", "tag":"tags"} +WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] +0 draft content +0 future content +2 pages created +0 tags created +0 categories created +in 4 ms +$ +``` + +The output says that it created 2 pages. Those are our new posts: + +```shell +$ find public -type f -name '*.html' | xargs ls -l +-rw-r--r-- 1 quoha staff 78 Sep 29 22:13 public/index.html +-rw-r--r-- 1 quoha staff 0 Sep 29 22:13 public/post/first/index.html +-rw-r--r-- 1 quoha staff 0 Sep 29 22:13 public/post/index.html +-rw-r--r-- 1 quoha staff 0 Sep 29 22:13 public/post/second/index.html +$ +``` + +The new files are empty because because the templates used to generate the content are empty. The homepage doesn't show the new content, either. We have to update the templates to add the posts. + +### List and Single Templates + +In Hugo, we have three major kinds of templates. There's the home page template that we updated previously. It is used only by the home page. We also have "single" templates which are used to generate output for a single content file. We also have "list" templates that are used to group multiple pieces of content before generating output. + +Generally speaking, list templates are named "list.html" and single templates are named "single.html." + +There are three other types of templates: partials, content views, and terms. We will not go into much detail on these. + +### Add Content to the Homepage + +The home page will contain a list of posts. Let's update its template to add the posts that we just created. The logic in the template will run every time we build the site. + +```html + + + + + {{ range first 10 .Data.Pages }} +

{{ .Title }}

+ {{ end }} + + + +``` + +Hugo uses the Go template engine. That engine scans the template files for commands which are enclosed between "{{" and "}}". In our template, the commands are: + +1. range +2. .Title +3. end + +The "range" command is an iterator. We're going to use it to go through the first ten pages. Every HTML file that Hugo creates is treated as a page, so looping through the list of pages will look at every file that will be created. + +The ".Title" command prints the value of the "title" variable. Hugo pulls it from the front matter in the Markdown file. + +The "end" command signals the end of the range iterator. The engine loops back to the top of the iteration when it finds "end." Everything between the "range" and "end" is evaluated every time the engine goes through the iteration. In this file, that would cause the title from the first ten pages to be output as heading level one. + +It's helpful to remember that some variables, like .Data, are created before any output files. Hugo loads every content file into the variable and then gives the template a chance to process before creating the HTML files. + +Build the web site and then verify the results. + +```shell + $ rm -rf public + $ hugo --verbose + INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 found taxonomies: map[string]string{"tag":"tags", "category":"categories"} + WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] + 0 draft content + 0 future content + 2 pages created + 0 tags created + 0 categories created + in 4 ms + $ find public -type f -name '*.html' | xargs ls -l + -rw-r--r-- 1 quoha staff 94 Sep 29 22:23 public/index.html + -rw-r--r-- 1 quoha staff 0 Sep 29 22:23 public/post/first/index.html + -rw-r--r-- 1 quoha staff 0 Sep 29 22:23 public/post/index.html + -rw-r--r-- 1 quoha staff 0 Sep 29 22:23 public/post/second/index.html + $ cat public/index.html + + + + +

second

+ +

first

+ + + + $ +``` + +Congratulations, the home page shows the title of the two posts. The posts themselves are still empty, but let's take a moment to appreciate what we've done. Your template now generates output dynamically. Believe it or not, by inserting the range command inside of those curly braces, you've learned everything you need to know to build a theme. All that's really left is understanding which template will be used to generate each content file and becoming familiar with the commands for the template engine. + +And, if that were entirely true, this tutorial would be much shorter. There are a few things to know that will make creating a new template much easier. Don't worry, though, that's all to come. + +### Add Content to the Posts + +We're working with posts, which are in the content/post/ directory. That means that their section is "post" (and if we don't do something weird, their type is also "post"). + +Hugo uses the section and type to find the template file for every piece of content. Hugo will first look for a template file that matches the section or type name. If it can't find one, then it will look in the _default/ directory. There are some twists that we'll cover when we get to categories and tags, but for now we can assume that Hugo will try post/single.html, then _default/single.html. + +Now that we know the search rule, let's see what we actually have available: + +```shell + $ find themes/zafta -name single.html | xargs ls -l + -rw-r--r-- 1 quoha staff 132 Sep 29 17:31 themes/zafta/layouts/_default/single.html +``` + +We could create a new template, post/single.html, or change the default. Since we don't know of any other content types, let's start with updating the default. + +Remember, any content that we haven't created a template for will end up using this template. That can be good or bad. Bad because I know that we're going to be adding different types of content and we're going to end up undoing some of the changes we've made. It's good because we'll be able to see immediate results. It's also good to start here because we can start to build the basic layout for the site. As we add more content types, we'll refactor this file and move logic around. Hugo makes that fairly painless, so we'll accept the cost and proceed. + +Please see the Hugo documentation on template rendering for all the details on determining which template to use. And, as the docs mention, if you're building a single page application (SPA) web site, you can delete all of the other templates and work with just the default single page. That's a refreshing amount of joy right there. + +#### Update the Template File + +```html + $ vi themes/zafta/layouts/_default/single.html + + + + {{ .Title }} + + +

{{ .Title }}

+ {{ .Content }} + + + :wq +``` + +Build the web site and verify the results. + + $ rm -rf public + $ hugo --verbose + INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 found taxonomies: map[string]string{"tag":"tags", "category":"categories"} + WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] + 0 draft content + 0 future content + 2 pages created + 0 tags created + 0 categories created + in 4 ms + + $ find public -type f -name '*.html' | xargs ls -l + -rw-r--r-- 1 quoha staff 94 Sep 29 22:40 public/index.html + -rw-r--r-- 1 quoha staff 125 Sep 29 22:40 public/post/first/index.html + -rw-r--r-- 1 quoha staff 0 Sep 29 22:40 public/post/index.html + -rw-r--r-- 1 quoha staff 128 Sep 29 22:40 public/post/second/index.html + + +```html $ cat public/post/first/index.html + + + + first + + +

first

+

my first post

+ + + + + $ cat public/post/second/index.html + + + + second + + +

second

+

my second post

+ + + + $ +``` + +Notice that the posts now have content. You can go to localhost:1313/post/first to verify. + +### Linking to Content + +The posts are on the home page. Let's add a link from there to the post. Since this is the home page, we'll update its template. + +```html + $ vi themes/zafta/layouts/index.html + + + + {{ range first 10 .Data.Pages }} +

{{ .Title }}

+ {{ end }} + + +``` + +Build the web site and verify the results. + +```shell + $ rm -rf public + $ hugo --verbose + INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/hugo.toml + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ + INFO: 2014/09/29 found taxonomies: map[string]string{"tag":"tags", "category":"categories"} + WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] + 0 draft content + 0 future content + 2 pages created + 0 tags created + 0 categories created + in 4 ms + + $ find public -type f -name '*.html' | xargs ls -l + -rw-r--r-- 1 quoha staff 149 Sep 29 22:44 public/index.html + -rw-r--r-- 1 quoha staff 125 Sep 29 22:44 public/post/first/index.html + -rw-r--r-- 1 quoha staff 0 Sep 29 22:44 public/post/index.html + -rw-r--r-- 1 quoha staff 128 Sep 29 22:44 public/post/second/index.html + + $ cat public/index.html + + + + +

second

+ +

first

+ + + + + $ +``` + +### Create a Post Listing + +We have the posts displaying on the home page and on their own page. We also have a file public/post/index.html that is empty. Let's make it show a list of all posts (not just the first ten). + +We need to decide which template to update. This will be a listing, so it should be a list template. Let's take a quick look and see which list templates are available. + +```shell + $ find themes/zafta -name list.html | xargs ls -l + -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html +``` + +As with the single post, we have to decide to update _default/list.html or create post/list.html. We still don't have multiple content types, so let's stay consistent and update the default list template. + +## Creating Top Level Pages + +Let's add an "about" page and display it at the top level (as opposed to a sub-level like we did with posts). + +The default in Hugo is to use the directory structure of the content/ directory to guide the location of the generated html in the public/ directory. Let's verify that by creating an "about" page at the top level: + +```markdown +$ vi content/about.md ++++ +title = "about" +description = "about this site" +date = "2014-09-27" +slug = "about time" ++++ + +## about us + +i'm speechless +:wq +``` +Generate the web site and verify the results. + +```shell + $ find public -name '*.html' | xargs ls -l + -rw-rw-r-- 1 mdhender staff 334 Sep 27 15:08 public/about-time/index.html + -rw-rw-r-- 1 mdhender staff 527 Sep 27 15:08 public/index.html + -rw-rw-r-- 1 mdhender staff 358 Sep 27 15:08 public/post/first-post/index.html + -rw-rw-r-- 1 mdhender staff 0 Sep 27 15:08 public/post/index.html + -rw-rw-r-- 1 mdhender staff 342 Sep 27 15:08 public/post/second-post/index.html +``` + +Notice that the page wasn't created at the top level. It was created in a sub-directory named 'about-time/'. That name came from our slug. Hugo will use the slug to name the generated content. It's a reasonable default, by the way, but we can learn a few things by fighting it for this file. + +One other thing. Take a look at the home page. + +```html + + + + +

creating a new theme

+

about

+

second

+

first

+ + +``` +Notice that the "about" link is listed with the posts? That's not desirable, so let's change that first. + +```html + + + + +

posts

+ {{ range first 10 .Data.Pages }} + {{ if eq .Type "post"}} +

{{ .Title }}

+ {{ end }} + {{ end }} + +

pages

+ {{ range .Data.Pages }} + {{ if eq .Type "page" }} +

{{ .Title }}

+ {{ end }} + {{ end }} + + + +``` +Generate the web site and verify the results. The home page has two sections, posts and pages, and each section has the right set of headings and links in it. + +But, that about page still renders to about-time/index.html. + +```bash + $ find public -name '*.html' | xargs ls -l + -rw-rw-r-- 1 mdhender staff 334 Sep 27 15:33 public/about-time/index.html + -rw-rw-r-- 1 mdhender staff 645 Sep 27 15:33 public/index.html + -rw-rw-r-- 1 mdhender staff 358 Sep 27 15:33 public/post/first-post/index.html + -rw-rw-r-- 1 mdhender staff 0 Sep 27 15:33 public/post/index.html + -rw-rw-r-- 1 mdhender staff 342 Sep 27 15:33 public/post/second-post/index.html +``` + +Knowing that hugo is using the slug to generate the file name, the simplest solution is to change the slug. Let's do it the hard way and change the permalink in the configuration file. + + $ vi hugo.toml + [permalinks] + page = "/:title/" + about = "/:filename/" + +Generate the web site and verify that this didn't work. Hugo lets "slug" or "URL" override the permalinks setting in the configuration file. Go ahead and comment out the slug in content/about.md, then generate the web site to get it to be created in the right place. + +## Sharing Templates + +If you've been following along, you probably noticed that posts have titles in the browser and the home page doesn't. That's because we didn't put the title in the home page's template (layouts/index.html). That's an easy thing to do, but let's look at a different option. + +We can put the common bits into a shared template that's stored in the themes/zafta/layouts/partials/ directory. + +### Create the Header and Footer Partials + +In Hugo, a partial is a sugar-coated template. Normally a template reference has a path specified. Partials are different. Hugo searches for them along a TODO defined search path. This makes it easier for end-users to override the theme's presentation. + +```html + $ vi themes/zafta/layouts/partials/header.html + + + + {{ .Title }} + + + :wq + + $ vi themes/zafta/layouts/partials/footer.html + + + :wq +``` + +### Update the Home Page Template to Use the Partials + +The most noticeable difference between a template call and a partials call is the lack of path: + + {{ template "theme/partials/header.html" . }} + +versus + + {{ partial "header.html" . }} + +Both pass in the context. + +Let's change the home page template to use these new partials. + +```html +{{ partial "header.html" . }} + +

posts

+{{ range first 10 .Data.Pages }} + {{ if eq .Type "post"}} +

{{ .Title }}

+ {{ end }} +{{ end }} + +

pages

+{{ range .Data.Pages }} + {{ if or (eq .Type "page") (eq .Type "about") }} +

{{ .Type }} - {{ .Title }} - {{ .RelPermalink }}

+ {{ end }} +{{ end }} +{{ partial "footer.html" . }} +``` + +Generate the web site and verify the results. The title on the home page is now "your title here", which comes from the "title" variable in the hugo.toml file. + +### Update the Default Single Template to Use the Partials + + $ vi themes/zafta/layouts/_default/single.html + {{ partial "header.html" . }} + +

{{ .Title }}

+ {{ .Content }} + + {{ partial "footer.html" . }} + :wq + +Generate the web site and verify the results. The title on the posts and the about page should both reflect the value in the markdown file. + +## Add “Date Published” to Posts + +It's common to have posts display the date that they were written or published, so let's add that. The front matter of our posts has a variable named "date." It's usually the date the content was created, but let's pretend that's the value we want to display. + +### Add “Date Published” to the Template + +We'll start by updating the template used to render the posts. The template code will look like: + +`{{ .Date.Format "Mon, Jan 2, 2006" }}` + +Posts use the default single template, so we'll change that file. + +```html + +{{ partial "header.html" . }} + +

{{ .Title }}

+

{{ .Date.Format "Mon, Jan 2, 2006" }}

+ {{ .Content }} + +{{ partial "footer.html" . }} +``` + +Generate the web site and verify the results. The posts now have the date displayed in them. There's a problem, though. The "about" page also has the date displayed. + +As usual, there are a couple of ways to make the date display only on posts. We could do an "if" statement like we did on the home page. Another way would be to create a separate template for posts. + +The "if" solution works for sites that have just a couple of content types. It aligns with the principle of "code for today," too. + +Let's assume, though, that we've made our site so complex that we feel we have to create a new template type. In Hugo-speak, we're going to create a section template. + +Let's restore the default single template before we forget. + +```html + + $ vi themes/zafta/layouts/_default/single.html + {{ partial "header.html" . }} + +

{{ .Title }}

+ {{ .Content }} + + {{ partial "footer.html" . }} +``` + +Now we'll update the post's version of the single template. If you remember Hugo's rules, the template engine will use this version over the default. + +```html + +{{ partial "header.html" . }} + +

{{ .Title }}

+

{{ .Date.Format "Mon, Jan 2, 2006" }}

+ {{ .Content }} + +{{ partial "footer.html" . }} +``` + +Note that we removed the date logic from the default template and put it in the post template. Generate the web site and verify the results. Posts have dates and the about page doesn't. + +### Don't Repeat Yourself + +DRY is a good design goal and Hugo does a great job supporting it. Part of the art of a good template is knowing when to add a new template and when to update an existing one. While you're figuring that out, accept that you'll be doing some refactoring. Hugo makes that easy and fast, so it's okay to delay splitting up a template. diff --git a/exampleSite/content/blog/emoji-support.md b/exampleSite/content/blog/emoji-support.md new file mode 100644 index 0000000..57c88c1 --- /dev/null +++ b/exampleSite/content/blog/emoji-support.md @@ -0,0 +1,99 @@ ++++ +author = "Hugo Authors" +title = "Emoji Support" +date = "2019-03-05" +description = "Guide to emoji usage in Hugo" +tags = ["emoji"] +image = "/images/artist.jpg" ++++ + +Emoji can be enabled in a Hugo project in a number of ways. + + +The `[emojify](https://gohugo.io/functions/emojify/)` function can be called directly in templates or [Inline Shortcodes](https://gohugo.io/templates/shortcode-templates/#inline-shortcodes). + +{{< youtube "https://www.youtube.com/watch?v=eW7Twd85m2g" >}} + +To enable emoji globally, set `enableEmoji` to `true` in your site’s [configuration](https://gohugo.io/getting-started/configuration/) and then you can type emoji shorthand codes directly in content files; e.g. + +

🙈 :see_no_evil: 🙉 :hear_no_evil: 🙊 :speak_no_evil:

+
+ +The [Emoji cheat sheet](http://www.emoji-cheat-sheet.com/) is a useful reference for emoji shorthand codes. + +*** + +**N.B.** The above steps enable Unicode Standard emoji characters and sequences in Hugo, however the rendering of these glyphs depends on the browser and the platform. To style the emoji you can either use a third party emoji font or a font stack; e.g. + +### Inline CSS + +```html + +``` + +### Javascript + +```javascript +function createEl(element) { + return document.createElement(element); +} + +function elem(selector, parent = document){ + let elem = parent.querySelector(selector); + return elem != false ? elem : false; +} + +let navBar = elem(`.${bar}`); +let nav = elem('.nav-body'); +let open = 'nav-open'; +let exit = 'nav-exit'; +let drop = 'nav-drop'; +let pop = 'nav-pop'; +let navDrop = elem(`.${drop}`); +let hidden = 'hidden'; + +``` + +### Swift + +```swift +class Person { + var residence: Residence? +} + +class Residence { + var rooms = [Room]() + var numberOfRooms: Int { + return rooms.count + } + + + subscript(i: Int) -> Room { + get { + return rooms[i] + } + set { + rooms[i] = newValue + } + } + + func printNumberOfRooms() { + print("The number of rooms is \(numberOfRooms)") + } + + var address: Address? + +} +``` diff --git a/exampleSite/content/blog/goisforlovers.md b/exampleSite/content/blog/goisforlovers.md new file mode 100644 index 0000000..ee3c6e0 --- /dev/null +++ b/exampleSite/content/blog/goisforlovers.md @@ -0,0 +1,339 @@ ++++ +title = "(Hu)go Template Primer" +description = "" +tags = [ +"go", +"golang", +"templates", +"themes", +"development", +] +date = "2014-04-02" +categories = [ +"Development", +"golang", +] +image = "/images/artist.jpg" ++++ + +Hugo uses the excellent [Go](https://golang.org/) [html/template](https://golang.org/pkg/html/template/) library for +its template engine. It is an extremely lightweight engine that provides a very +small amount of logic. In our experience that it is just the right amount of +logic to be able to create a good static website. If you have used other +template systems from different languages or frameworks you will find a lot of +similarities in Go templates. + +This document is a brief primer on using Go templates. The [Go docs](https://golang.org/pkg/html/template/) +provide more details. + +## Introduction to Go Templates + +Go templates provide an extremely simple template language. It adheres to the +belief that only the most basic of logic belongs in the template or view layer. +One consequence of this simplicity is that Go templates parse very quickly. + +A unique characteristic of Go templates is they are content aware. Variables and +content will be sanitized depending on the context of where they are used. More +details can be found in the [Go docs](https://golang.org/pkg/html/template/). + +## Basic Syntax + +Golang templates are HTML files with the addition of variables and +functions. + +**Go variables and functions are accessible within {{ }}** + +Accessing a predefined variable "foo": + + {{ foo }} + +**Parameters are separated using spaces** + +Calling the add function with input of 1, 2: + + {{ add 1 2 }} + +**Methods and fields are accessed via dot notation** + +Accessing the Page Parameter "bar" + + {{ .Params.bar }} + +**Parentheses can be used to group items together** + + {{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }} + +## Variables + +Each Go template has a struct (object) made available to it. In hugo each +template is passed either a page or a node struct depending on which type of +page you are rendering. More details are available on the +[variables](/layout/variables) page. + +A variable is accessed by referencing the variable name. + + {{ .Title }} + +Variables can also be defined and referenced. + + {{ $address := "123 Main St."}} + {{ $address }} + +## Functions + +Go template ship with a few functions which provide basic functionality. The Go +template system also provides a mechanism for applications to extend the +available functions with their own. [Hugo template +functions](/layout/functions) provide some additional functionality we believe +are useful for building websites. Functions are called by using their name +followed by the required parameters separated by spaces. Template +functions cannot be added without recompiling hugo. + +**Example:** + + {{ add 1 2 }} + +## Includes + +When including another template you will pass to it the data it will be +able to access. To pass along the current context please remember to +include a trailing dot. The templates location will always be starting at +the /layout/ directory within Hugo. + +**Example:** + + {{ template "chrome/header.html" . }} + +## Logic + +Go templates provide the most basic iteration and conditional logic. + +### Iteration + +Just like in Go, the Go templates make heavy use of range to iterate over +a map, array or slice. The following are different examples of how to use +range. + +**Example 1: Using Context** + + {{ range array }} + {{ . }} + {{ end }} + +**Example 2: Declaring value variable name** + + {{range $element := array}} + {{ $element }} + {{ end }} + +**Example 2: Declaring key and value variable name** + + {{range $index, $element := array}} + {{ $index }} + {{ $element }} + {{ end }} + +### Conditionals + +If, else, with, or, & and provide the framework for handling conditional +logic in Go Templates. Like range, each statement is closed with `end`. + +Go Templates treat the following values as false: + +* false +* 0 +* any array, slice, map, or string of length zero + +**Example 1: If** + + {{ if isset .Params "title" }}

{{ index .Params "title" }}

{{ end }} + +**Example 2: If -> Else** + + {{ if isset .Params "alt" }} + {{ index .Params "alt" }} + {{else}} + {{ index .Params "caption" }} + {{ end }} + +**Example 3: And & Or** + + {{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}} + +**Example 4: With** + +An alternative way of writing "if" and then referencing the same value +is to use "with" instead. With rebinds the context `.` within its scope, +and skips the block if the variable is absent. + +The first example above could be simplified as: + + {{ with .Params.title }}

{{ . }}

{{ end }} + +**Example 5: If -> Else If** + + {{ if isset .Params "alt" }} + {{ index .Params "alt" }} + {{ else if isset .Params "caption" }} + {{ index .Params "caption" }} + {{ end }} + +## Pipes + +One of the most powerful components of Go templates is the ability to +stack actions one after another. This is done by using pipes. Borrowed +from unix pipes, the concept is simple, each pipeline's output becomes the +input of the following pipe. + +Because of the very simple syntax of Go templates, the pipe is essential +to being able to chain together function calls. One limitation of the +pipes is that they only can work with a single value and that value +becomes the last parameter of the next pipeline. + +A few simple examples should help convey how to use the pipe. + +**Example 1 :** + + {{ if eq 1 1 }} Same {{ end }} + +is the same as + + {{ eq 1 1 | if }} Same {{ end }} + +It does look odd to place the if at the end, but it does provide a good +illustration of how to use the pipes. + +**Example 2 :** + + {{ index .Params "disqus_url" | html }} + +Access the page parameter called "disqus_url" and escape the HTML. + +**Example 3 :** + + {{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}} + Stuff Here + {{ end }} + +Could be rewritten as + + {{ isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" | if }} + Stuff Here + {{ end }} + +## Context (aka. the dot) + +The most easily overlooked concept to understand about Go templates is that {{ . }} +always refers to the current context. In the top level of your template this +will be the data set made available to it. Inside of a iteration it will have +the value of the current item. When inside of a loop the context has changed. . +will no longer refer to the data available to the entire page. If you need to +access this from within the loop you will likely want to set it to a variable +instead of depending on the context. + +**Example:** + + {{ $title := .Site.Title }} + {{ range .Params.tags }} +
  • {{ . }} - {{ $title }}
  • + {{ end }} + +Notice how once we have entered the loop the value of {{ . }} has changed. We +have defined a variable outside of the loop so we have access to it from within +the loop. + +# Hugo Parameters + +Hugo provides the option of passing values to the template language +through the site configuration (for sitewide values), or through the meta +data of each specific piece of content. You can define any values of any +type (supported by your front matter/config format) and use them however +you want to inside of your templates. + +## Using Content (page) Parameters + +In each piece of content you can provide variables to be used by the +templates. This happens in the [front matter](/content/front-matter). + +An example of this is used in this documentation site. Most of the pages +benefit from having the table of contents provided. Sometimes the TOC just +doesn't make a lot of sense. We've defined a variable in our front matter +of some pages to turn off the TOC from being displayed. + +Here is the example front matter: + +```markdown +--- +title: "Permalinks" +date: "2013-11-18" +aliases: + - "/doc/permalinks/" +groups: ["extras"] +groups_weight: 30 +notoc: true +--- +``` + +Here is the corresponding code inside of the template: + +```html + {{ if not .Params.notoc }} +
    + {{ .TableOfContents }} +
    + {{ end }} +``` + +## Using Site (config) Parameters + +In your top-level configuration file (eg, `config.yaml`) you can define site +parameters, which are values which will be available to you in chrome. + +For instance, you might declare: + +```yaml +params: + CopyrightHTML: "Copyright © 2013 John Doe. All Rights Reserved." + TwitterUser: "spf13" + SidebarRecentLimit: 5 +``` + +Within a footer layout, you might then declare a `