From 8ba41fc32c9e448475fcce539e979f199e51b7bd Mon Sep 17 00:00:00 2001 From: Spedon <70063177+Sped0n@users.noreply.github.com> Date: Sun, 7 Jan 2024 23:16:55 +0800 Subject: [PATCH] v0.0.5 (#219) * feat: refactor condition for checking `site.Params.bundled` - Add default condition for checking if `site.Params.bundled` is true or false * refactor: update info page content * chore: update site description * refactor: refactor variable assignments and return statement in menu template - Change the variable assignment from `.DirName` to `.Identifier` in the file `layouts/_default/single.json` - Change the variable assignments in the file `layouts/partials/function/currentMenuItem.html`: - From `$dirName := ""` to `$identifier := ""` - From `$id := -1` to `$title := ""` and `$weight := -1` - From `$dirName = .Identifier` to `$identifier = .Identifier`, `$title = .Title`, and `$weight = .Weight` - Change the return statement in the file `layouts/partials/function/currentMenuItem.html` from `(dict "DirName" $dirName "ID" $id)` to `(dict "Identifier" $identifier "Title" $title "Weight" $weight)` * feat: update nav links structure for current link styling - Remove javascript code related to setting current link style and title - Update nav links to use updated HTML structure for current link styling * feat: update page titles and meta tags in layout files - Update the `baseof.html` layout to include the current page title in the `` tag - Add OpenGraph meta tags for the page title and description in `meta.html` layout --- assets/ts/nav.ts | 21 ------------- exampleSite/config/_default/params.toml | 2 +- exampleSite/content/Info/index.md | 4 +-- layouts/404.html | 5 --- layouts/_default/baseof.html | 9 +++--- layouts/_default/single.html | 15 +++------ layouts/_default/single.json | 2 +- .../partials/function/currentMenuItem.html | 12 ++++--- layouts/partials/head/link.html | 2 +- layouts/partials/head/meta.html | 31 +++++++++++++------ layouts/partials/nav.html | 20 ++++++++++-- static/bundled/js/main.js | 2 +- 12 files changed, 62 insertions(+), 63 deletions(-) diff --git a/assets/ts/nav.ts b/assets/ts/nav.ts index 13caa42..911551c 100644 --- a/assets/ts/nav.ts +++ b/assets/ts/nav.ts @@ -31,27 +31,6 @@ const indexDispNums = Array.from( indexDiv.getElementsByClassName('num') ) as HTMLSpanElement[] -// links div -const linksDiv = document.getElementsByClassName('links').item(0) as HTMLDivElement - -// links -const links = Array.from(linksDiv.getElementsByClassName('link')) as HTMLAnchorElement[] - -// current link index -const currentLinkIndex = document - .getElementById('main') - ?.getAttribute('currentMenuItemIndex') as string - -// set current link -for (const [index, link] of links.entries()) { - if (index === parseInt(currentLinkIndex)) { - // set current link style - link.classList.add('current') - // set current link title (only if not home) - if (index !== 0) document.title = link.innerText + ' | ' + document.title - } -} - /** * init */ diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index b8f3dce..fc82038 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -1,5 +1,5 @@ # description of the site (will be placed in meta) -description = "Bridget is a minimal Hugo theme designed for photographers / visual artists." +description = "Bridget is a minimal Hugo theme designed for photographers/visual artists." # use bundled js and css # * if you want to build the js and css from scratch, set this to false and run `npm install` and `npm run build` # * tldr: set this to false if you want to develop and edit the js and css diff --git a/exampleSite/content/Info/index.md b/exampleSite/content/Info/index.md index c129d8f..c95d0ca 100644 --- a/exampleSite/content/Info/index.md +++ b/exampleSite/content/Info/index.md @@ -10,9 +10,9 @@ menu: unifiedAlt: '' --- -Bridget is a _minimal_ Hugo theme designed for photographers / visual artists. +Bridget is a _minimal_ Hugo theme designed for photographers/visual artists. -The inspiration for this theme came from a video by <u>[Hyperlexed](https://www.youtube.com/@Hyperplexed)</u>, which can be found <u>[here](https://www.youtube.com/watch?v=Jt3A2lNN2aE)</u>. Initially, it was designed using pure TypeScript and CSS. However, after website designer <u>[Tyler McRobert](https://tylermcrobert.com)</u> made the source code publicly available, the whole project was modified to mimic the original design. The animations in Bridget are achieved using gsap and swiper. In essence, it is more like a porting of the original design into Hugo. +The inspiration for this theme came from a video by <u>[Hyperlexed](https://www.youtube.com/@Hyperplexed)</u>, which can be found <u>[here](https://www.youtube.com/watch?v=Jt3A2lNN2aE)</u>. Initially, it was developed using raw TypeScript and CSS. However, after website designer <u>[Tyler McRobert](https://tylermcrobert.com)</u> made the source code publicly available, I realized that I have invented many unnecessary components, and this project was modified to porting the original design to hugo while focussing on _performance_. Once again, great shout out to <u>[Tyler McRobert](https://tylermcrobert.com)</u> for his inspiration to this project. diff --git a/layouts/404.html b/layouts/404.html index 9ac594c..50aff5a 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -1,9 +1,4 @@ {{- define "main" -}} - {{- $params := .Scratch.Get "params" -}} - {{- $currentPage := . -}} - {{- with partial "function/currentMenuItem.html" . -}} - <script>document.getElementById("main").setAttribute("currentMenuItemIndex", "{{- (sub .ID 1) -}}")</script> - {{- end -}} <div class="container"> {{- partial "nav.html" . -}} </div> diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index a4d19d8..342f367 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -3,11 +3,10 @@ <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>{{ site.Title }} - {{- partial "head/link.html" -}} - {{- partial "head/meta.html" -}} - {{- partial "head/seo.html" -}} - {{- partial "head/favicon.html" -}} + {{- partial "head/link.html" . -}} + {{- partial "head/meta.html" . -}} + {{- partial "head/seo.html" . -}} + {{- partial "head/favicon.html" . -}}
diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 214cfef..dc38d44 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,14 +1,9 @@ {{- define "main" -}} - {{- $params := .Scratch.Get "params" -}} - {{- $currentPage := . -}} - {{- with partial "function/currentMenuItem.html" . -}} - - {{- end -}} +
{{- partial "nav.html" . -}}
diff --git a/layouts/_default/single.json b/layouts/_default/single.json index 111efd3..f1d391e 100644 --- a/layouts/_default/single.json +++ b/layouts/_default/single.json @@ -3,7 +3,7 @@ {{- $params := .Page.Params | merge .Site.Params.Page -}} {{- with partial "function/currentMenuItem.html" . -}} - {{- $Path = .DirName -}} + {{- $Path = .Identifier -}} {{- end -}} {{- $gallery := site.GetPage $Path -}} diff --git a/layouts/partials/function/currentMenuItem.html b/layouts/partials/function/currentMenuItem.html index a84d487..1502602 100644 --- a/layouts/partials/function/currentMenuItem.html +++ b/layouts/partials/function/currentMenuItem.html @@ -1,15 +1,17 @@ {{- $currentPage := . -}} -{{- $dirName := "" -}} -{{- $id := -1 -}} +{{- $identifier := "" -}} +{{- $title := "" -}} +{{- $weight := -1 -}} {{- range site.Menus.main -}} {{ $menu_item_url := .URL | relLangURL }} {{ $page_url:= $currentPage.RelPermalink | relLangURL }} {{ if eq $menu_item_url $page_url }} - {{- $dirName = .Identifier -}} - {{- $id = .Weight -}} + {{- $identifier = .Identifier -}} + {{- $title = .Title -}} + {{- $weight = .Weight -}} {{- end -}} {{- end -}} -{{- return (dict "DirName" $dirName "ID" $id) -}} +{{- return (dict "Identifier" $identifier "Title" $title "Weight" $weight) -}} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index 143c2e4..ad68af9 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -8,7 +8,7 @@ {{- partial "plugin/style.html" $style -}} {{/* main style */}} -{{- if site.Params.bundled -}} +{{- if (site.Params.bundled | default true) -}} {{- $style := dict "Link" "/bundled/css/style.min.css" "Defer" true -}} {{- partial "plugin/style.html" $style -}} {{- else -}} diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html index 2afdbc2..652218d 100644 --- a/layouts/partials/head/meta.html +++ b/layouts/partials/head/meta.html @@ -1,9 +1,22 @@ - - - +{{/* Title */}} +{{- $page_title := "" -}} +{{- with partial "function/currentMenuItem.html" . -}} + {{ $page_title = printf "%s" site.Title | printf "%s%s" " | " | printf "%s%s" .Title | printf "%s" }} +{{- end -}} +{{ $page_title }} + +{{/* Basic */}} + + + + +{{/* Opengraph */}} + + + + + + + +{{/* Generator */}} +{{ hugo.Generator }} diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html index bfeeb2d..f2592aa 100644 --- a/layouts/partials/nav.html +++ b/layouts/partials/nav.html @@ -4,14 +4,30 @@