From cbd2f451c2e077bc19dba8df71f832a709c4bc5e Mon Sep 17 00:00:00 2001 From: nodejh Date: Mon, 16 Aug 2021 12:07:52 +0800 Subject: feat: support custom css and custom js --- README-zh_CN.md | 15 +++++++++++++++ README.md | 16 ++++++++++++++++ exampleSite/config.yaml | 12 +++++++++++- exampleSite/content/posts/test.md | 2 +- layouts/partials/comment.html | 12 +++++------- layouts/partials/footer.html | 10 ++++++++++ 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 diff --git a/README.md b/README.md index ccf1e20..05d7d5a 100644 --- a/README.md +++ b/README.md @@ -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 }} -
- - {{ template "_internal/disqus.html" . }} -
- {{ end }} +{{ if or (and .Site.Params.enableComments (ne .Params.enableComments false)) (eq .Params.enableComments true) }} +
+ + {{ template "_internal/disqus.html" . }} +
{{ 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 @@ {{ end }} + +{{ range .Site.Params.customJS }} + {{ if ( or ( hasPrefix . "http://" ) ( hasPrefix . "https://" ) ) }} + + + {{ else }} + + + {{ 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 }} + +{{ range .Site.Params.customCSS }} + {{ if ( or ( hasPrefix . "http://" ) ( hasPrefix . "https://" ) ) }} + + + {{ else }} + + + {{ end }} +{{ end }} + {{ if .Site.Params.enableGoogleAnalytics }} -- cgit v1.2.3