diff options
author | nodejh <jianghangscu@gmail.com> | 2021-08-16 07:07:52 +0300 |
---|---|---|
committer | nodejh <jianghangscu@gmail.com> | 2021-08-16 07:07:52 +0300 |
commit | cbd2f451c2e077bc19dba8df71f832a709c4bc5e (patch) | |
tree | db8a3424248316f6e72027ce4b94df56b0ea69de | |
parent | 86383a750ecdb2a6d23558fc3ef69c1541e57299 (diff) |
feat: support custom css and custom js
-rw-r--r-- | README-zh_CN.md | 15 | ||||
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | exampleSite/config.yaml | 12 | ||||
-rw-r--r-- | exampleSite/content/posts/test.md | 2 | ||||
-rw-r--r-- | layouts/partials/comment.html | 12 | ||||
-rw-r--r-- | layouts/partials/footer.html | 10 | ||||
-rw-r--r-- | layouts/partials/head.html | 11 |
7 files changed, 69 insertions, 9 deletions
diff --git a/README-zh_CN.md b/README-zh_CN.md index 5add95f..34ff44a 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -148,6 +148,21 @@ enableComments = false +++ ``` +### 3.2 自定义 CSS 和 JS + +你可以将自定义 CSS 和 JS 放在 `static` 中,也可以使用远程的 CSS 或 JS 文件。 + +例如: + +```yaml +customCSS: + - css/custom.css # local css in `static/css/custom.css` + - https://example.com/custom.css # remote css +customJS: + - js/custom.js # local js in `static/js/custom.js` + - https://example.com/custom.js # remote js +``` + ## License @@ -147,6 +147,22 @@ enableComments = false +++ ``` +### 3.2 Custom CSS and JS + +You can put your custom css and js files to `static` directory, or use remote css and js files which start with `http://` or `https://`. + +For example: + +```yaml +customCSS: + - css/custom.css # local css in `static/css/custom.css` + - https://example.com/custom.css # remote css +customJS: + - js/custom.js # local js in `static/js/custom.js` + - https://example.com/custom.js # remote js +``` + + ## License [MIT](https://github.com/nodejh/hugo-theme-mini/blob/master/LICENSE.md) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index bf4b20e..0a7ba90 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -62,6 +62,16 @@ params: # Extra links in navigation links: - # e.g. + ## e.g. # - name: Project # path: /project + + # You can put your custom css and js to `static` directory, or use remote css and js files which start with `http://` or `https://` + customCSS: + ## e.g. + # - css/custom.css # local css in `static/css/custom.css` + # - https://example.com/custom.css # remote css + customJS: + ## e.g. + # - js/custom.js # local js in `static/js/custom.js` + # - https://example.com/custom.js # remote js
\ No newline at end of file diff --git a/exampleSite/content/posts/test.md b/exampleSite/content/posts/test.md index 72265e4..bf9136c 100644 --- a/exampleSite/content/posts/test.md +++ b/exampleSite/content/posts/test.md @@ -1,7 +1,7 @@ +++ author = "Test" title = "Code Content" -date = "2019-03-10" +date = "2021-03-10" description = "A brief description of Hugo Shortcodes" tags = [ "shortcodes", diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html index d4d9dd5..f7a16a8 100644 --- a/layouts/partials/comment.html +++ b/layouts/partials/comment.html @@ -1,8 +1,6 @@ -{{ if .Site.Params.enableComments }} - {{ if ne .Params.enableComments false }} - <div id="comment"> - <!-- https://gohugo.io/templates/internal/#use-the-disqus-template --> - {{ template "_internal/disqus.html" . }} - </div> - {{ end }} +{{ if or (and .Site.Params.enableComments (ne .Params.enableComments false)) (eq .Params.enableComments true) }} + <div id="comment"> + <!-- https://gohugo.io/templates/internal/#use-the-disqus-template --> + {{ template "_internal/disqus.html" . }} + </div> {{ end }}
\ No newline at end of file diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 899b551..833c955 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -22,3 +22,13 @@ </div> {{ end }} </footer> + +{{ range .Site.Params.customJS }} + {{ if ( or ( hasPrefix . "http://" ) ( hasPrefix . "https://" ) ) }} + <!-- remote js --> + <script src="{{ . }}"></script> + {{ else }} + <!-- local js --> + <script src="{{ $.Site.BaseURL }}{{ . }}"></script> + {{ end }} +{{ end }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 277b8c7..79d9236 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -11,6 +11,17 @@ {{ end }} <link rel="stylesheet" href="{{ "/css/style.css" | relURL }}"> + +{{ range .Site.Params.customCSS }} + {{ if ( or ( hasPrefix . "http://" ) ( hasPrefix . "https://" ) ) }} + <!-- remote css --> + <link rel="stylesheet" href="{{ . }}"> + {{ else }} + <!-- local css --> + <link rel="stylesheet" href="{{ $.Site.BaseURL }}{{ . }}"> + {{ end }} +{{ end }} + <link rel="shortcut icon" href="{{ "/images/favicon.ico" | relURL }}" type="image/x-icon" /> {{ if .Site.Params.enableGoogleAnalytics }} |