Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for functional scripts to be included in the page header #1203

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module.exports = require('neostandard')({
ignores: [
'assets/js/critical/languageSelector.js',
'assets/js/critical/color.js',
'assets/js/functional/languageSelector.js',
'assets/js/functional/color.js',
'assets/js/analytics.js',
'assets/js/flexsearch.js',
'assets/js/navbar.js',
Expand Down
49 changes: 0 additions & 49 deletions exampleSite/assets/js/critical/_cookie.js

This file was deleted.

38 changes: 0 additions & 38 deletions exampleSite/assets/js/critical/_cookie2.js

This file was deleted.

20 changes: 20 additions & 0 deletions exampleSite/config/_default/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,23 @@ home = ["HTML", "RSS", "REDIR"]
workspace = "hinode.work"
[[module.imports]]
path = "github.com/gethinode/hinode"
[[module.imports]]
path = "github.com/gethinode/mod-bootstrap"
[[module.imports]]
path = "github.com/gethinode/mod-cookieyes"
[[module.imports]]
path = "github.com/gethinode/mod-flexsearch/v2"
[[module.imports]]
path = "github.com/gethinode/mod-fontawesome"
[[module.imports]]
path = "github.com/gethinode/mod-google-analytics"
[[module.imports]]
path = "github.com/gethinode/mod-katex"
[[module.imports]]
path = "github.com/gethinode/mod-leaflet"
[[module.imports]]
path = "github.com/gethinode/mod-lottie"
[[module.imports]]
path = "github.com/gethinode/mod-simple-datatables"
[[module.imports]]
path = "github.com/gethinode/mod-utils/v2"
4 changes: 1 addition & 3 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,5 @@
hinode = "https://gethinode.com"

[modules.cookieyes]
state = "immediate"
category = "necessary"
id = "a54b5553f349dd13bd225f8e"
force = true
force = false
1 change: 1 addition & 0 deletions exampleSite/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ module github.com/gethinode/hinode/exampleSite

go 1.19

require github.com/gethinode/mod-cookieyes v1.0.0 // indirect
2 changes: 2 additions & 0 deletions exampleSite/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/gethinode/hinode v0.22.5 h1:zpjSDgWQVbq4BjPduxwexQB18gawFeinzPkaRRTs2
github.com/gethinode/hinode v0.22.5/go.mod h1:hsskrlBRnTbpCjrDtGbK8C1VYGML7ezHtCDGDiYL2mQ=
github.com/gethinode/mod-bootstrap v1.2.2 h1:Q8E04OKWr9owk7nhQ/NBukUgSFhsECxZsOLEaf5oeiQ=
github.com/gethinode/mod-bootstrap v1.2.2/go.mod h1:DcpPc2cNaXUPGEvhD7npuEEPA7573NvakTlrwFbyjr8=
github.com/gethinode/mod-cookieyes v1.0.0 h1:KTkK67uugji9pzYJJalvNhdECHgG1DzPtyeaYL0Xm/0=
github.com/gethinode/mod-cookieyes v1.0.0/go.mod h1:VrBUKm5apop6KIb+R8eRqvlf3AAPnv5aMajL0RorIjY=
github.com/gethinode/mod-flexsearch v1.9.0 h1:AE+w7QeZTxh36JNTG+CASDLxaqlCZKn+EUD6ulnPGak=
github.com/gethinode/mod-flexsearch v1.9.0/go.mod h1:L8hrnpupx27cez2ObMX8gWnhbW6qss4HGH1Ea4UaBRQ=
github.com/gethinode/mod-fontawesome v1.8.1 h1:iyvULrpaGizQoI5Vl9WjFYcMGWefdyG90NGK2UKax+k=
Expand Down
26 changes: 26 additions & 0 deletions exampleSite/layouts/partials/templates/script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
Copyright © 2024 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->

<!-- Initialize arguments -->
{{ $args := partial "utilities/InitArgs.html" (dict "structure" "script" "args" .) }}
{{ if $args.err }}
{{ partial "utilities/LogErr.html" (dict
"partial" "templates/script.html"
"msg" "Invalid arguments"
"details" $args.errmsg
"file" page.File
)}}
{{ end }}

<!-- Initialize local arguments -->
{{ $category := cond (ne $args.category "other") $args.category "" }}

<!-- Main code -->
<script src="{{ $args.link }}"
{{- with $category }} data-cookieyes="cookieyes-{{ . }}"{{ end -}}
{{- with $args.integrity }}integrity="{{ . }}" crossorigin="anonymous"{{ end }}
{{- with $args.state }} {{ . | safeHTMLAttr }}{{ end -}}>
</script>
1 change: 1 addition & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
{{- partial "footer/scripts.html" (dict "page" . "type" "critical") -}}
{{- partial "footer/scripts.html" (dict "page" . "type" "functional") -}}
{{ block "head" . }}{{ end -}}
</head>

Expand Down
1 change: 1 addition & 0 deletions layouts/alias.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<noscript><meta http-equiv="refresh" content="0; url={{ .Permalink }}"></noscript>
{{ if site.Params.main.enableLanguageSelectionStorage }}
{{- partial "footer/scripts.html" (dict "page" page "type" "critical") -}}
{{- partial "footer/scripts.html" (dict "page" page "type" "functional") -}}
{{ else }}
<script src='{{ partial "utilities/GetStaticURL" (dict "url" "js/alias.js") }}'></script>
{{ end }}
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/footer/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@
<!-- Initialize local arguments -->
{{ $patterns := dict
"critical" "js/critical/**.js"
"functional" "js/functional/**.js"
"core" "{js/*.js,js/vendor/**.js}"
}}

{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{ $state := "immediate" }}

{{ $config := dict }}
{{ if ne $args.type "critical" }}
{{ if not (in (slice "critical" "functional") $args.type) }}
{{ $config = $args.page.Scratch.Get "modules" }}
{{ if not $config }}
{{ errorf "partial [footer/scripts.html] - Cannot initialize module configuration" }}
Expand Down Expand Up @@ -120,12 +121,13 @@

<!-- Main code -->
{{ if not $error }}
<!-- Bundle the critical scripts as single file -->
{{ if eq $args.type "critical" }}
<!-- Bundle the critical and functional scripts as single file -->
{{ if in (slice "critical" "functional") $args.type }}
{{ partial "partials/bundle-script.html" (dict
"page" $args.page
"match" (index $patterns $args.type)
"destination" (printf "js/%s.bundle.js" $args.type)
"destination" (printf "js/%s.bundle.js" "critical")
"cat" (cond (eq $args.type "functional") $args.type "")
"localize" $localize
"skipTemplate" $skipTemplate
"absoluteURL" $absoluteURL
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.27.0-alpha9",
"version": "0.27.0-beta",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",
Expand Down