Allow optional processing of assets through Hugo Pipes

This commit is contained in:
Regis Philibert 2021-01-11 15:28:09 -05:00
parent 16fc5e6d80
commit 37c8143a2a
18 changed files with 86 additions and 17811 deletions

2
.gitignore vendored
View File

@ -18,6 +18,7 @@ nbproject/
.bin/node_modules/
/node_modules/
src/node_modules/
exampleSite/node_modules/
src/npm-debug.log.*
npm-debug.log
/npm-debug.log*
@ -28,3 +29,4 @@ npm-debug.log
/junit.xml
partials/structure/stylesheet.html

View File

@ -153,6 +153,30 @@ For example, if your css files are `static/css/custom.css` and `static/css/custo
custom_css = ["css/custom.css","css/custom2.css"]
```
### Processed CSS
By default, Ananke will read a preprocessed stylesheet from `/assets/ananke/dist/main.[hash].css`. If you want to have Hugo process the stylesheet for you thus allowing better customisation using Hugo's unison file system, you need to:
1. From the root of your project: `$ hugo mod npm pack`.
This will generate a `package.json` for your project, or append the npm packages required by the theme to your existing `package.json`.
2. Still from the root of your project: `$ npm install`
3. Set the following site Parameter to true:
```
[params]
ananke_process_css = true
```
You're all set an can run Hugo.
#### Overwrite some imported file
To have your own `_code.css` imported and processed by the theme. Add `/assets/ananke/css/_code.css` to your project.
#### Add a new import
Create your own `/assets/ananke/css/` directory at the root of your project, drop your files in there, and create your own `/main.css` with your own import statements. Don't forget to include the existing import statement from the theme's own `main.css`.
### Show Reading Time and Word Count
If you add a key of `show_reading_time` true to either the Config Params, a page or section's front matter, articles will show the reading time and word count.

View File

@ -1,7 +0,0 @@
module.exports = {
plugins: [
require("postcss-import")({
path: ["/assets/ananke/css"],
})
],
};

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ baseURL = "https://example.com"
languageCode = "en-us"
theme = "gohugo-theme-ananke"
themesDir = "../.."
resourceDir = "../resources"
DefaultContentLanguage = "en"
SectionPagesMenu = "main"

View File

@ -1,4 +1,5 @@
{{ $script := .Site.Data.webpack_assets.app }}
{{ with $script.js }}
<script src="{{ relURL (printf "%s%s" "dist/" .) }}"></script>
{{ with resources.Get "/ananke/js/main.js" }}
{{ $js := . | js.Build }}
<script src="{{ .RelPermalink }}"></script>
{{ end }}

View File

@ -1,10 +1,17 @@
{{ if site.Params.ananke_process_css }}
{{ with resources.Get "/ananke/css/main.css" }}
{{ $settings := dict "config" "/assets/ananke/css/postcss.config.css" }}
{{ $style := . | resources.PostCSS }}
{{ $options := (dict "targetPath" "/ananke/css/main.css" "enableSourceMap" true "precision" 6 "includePaths" (slice "node_modules")) }}
{{ $style := . | resources.ToCSS $options | resources.PostCSS (dict "use" "postcss-cssnext") | minify }}
{{ with $style }}
<link rel="stylesheet" href="{{ .RelPermalink }}" >
{{ end }}
{{ end }}
{{ else }}
{{ with resources.GetMatch "/ananke/dist/main.*.css" }}
<link rel="stylesheet" href="{{ .RelPermalink }}" >
{{ end }}
{{ end }}
{{ range .Site.Params.custom_css }}
<link rel="stylesheet" href="{{ relURL (.) }}">
{{ end }}

132
package-lock.json generated
View File

@ -1,132 +0,0 @@
{
"name": "gohugo-default-theme",
"version": "2.5.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"auto-changelog": {
"version": "1.16.1",
"resolved": "https://registry.npmjs.org/auto-changelog/-/auto-changelog-1.16.1.tgz",
"integrity": "sha512-1OMUN5UWWhKtlEMpGUfbLFcZHDf4IXMNU4SsGs44xTlSBhjgTOx9ukbahoC7hTqIm6+sRAnlAbLY4UjbDZY18A==",
"dev": true,
"requires": {
"commander": "^3.0.1",
"core-js": "^3.2.1",
"handlebars": "^4.1.2",
"lodash.uniqby": "^4.7.0",
"node-fetch": "^2.6.0",
"parse-github-url": "^1.0.2",
"regenerator-runtime": "^0.13.3",
"semver": "^6.3.0"
}
},
"commander": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/commander/-/commander-3.0.2.tgz",
"integrity": "sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==",
"dev": true
},
"core-js": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.3.4.tgz",
"integrity": "sha512-BtibooaAmSOptGLRccsuX/dqgPtXwNgqcvYA6kOTTMzonRxZ+pJS4e+6mvVutESfXMeTnK8m3M+aBu3bkJbR+w==",
"dev": true
},
"handlebars": {
"version": "4.4.5",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.5.tgz",
"integrity": "sha512-0Ce31oWVB7YidkaTq33ZxEbN+UDxMMgThvCe8ptgQViymL5DPis9uLdTA13MiRPhgvqyxIegugrP97iK3JeBHg==",
"dev": true,
"requires": {
"neo-async": "^2.6.0",
"optimist": "^0.6.1",
"source-map": "^0.6.1",
"uglify-js": "^3.1.4"
}
},
"lodash.uniqby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz",
"integrity": "sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI=",
"dev": true
},
"minimist": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
"integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=",
"dev": true
},
"neo-async": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz",
"integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==",
"dev": true
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==",
"dev": true
},
"optimist": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
"integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=",
"dev": true,
"requires": {
"minimist": "~0.0.1",
"wordwrap": "~0.0.2"
}
},
"parse-github-url": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/parse-github-url/-/parse-github-url-1.0.2.tgz",
"integrity": "sha512-kgBf6avCbO3Cn6+RnzRGLkUsv4ZVqv/VfAYkRsyBcgkshNvVBkRn1FEZcW0Jb+npXQWm2vHPnnOqFteZxRRGNw==",
"dev": true
},
"regenerator-runtime": {
"version": "0.13.3",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
"integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==",
"dev": true
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"uglify-js": {
"version": "3.6.4",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.4.tgz",
"integrity": "sha512-9Yc2i881pF4BPGhjteCXQNaXx1DCwm3dtOyBaG2hitHjLWOczw/ki8vD1bqyT3u6K0Ms/FpCShkmfg+FtlOfYA==",
"dev": true,
"optional": true,
"requires": {
"commander": "~2.20.3",
"source-map": "~0.6.1"
},
"dependencies": {
"commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true,
"optional": true
}
}
},
"wordwrap": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=",
"dev": true
}
}
}

View File

@ -1,34 +1,41 @@
{
"name": "gohugo-theme-ananke",
"version": "2.7.0",
"description": "Base Theme to start Hugo Sites",
"author": "budparr",
"bugs": {
"url": "https://github.com/theNewDynamic/gohugo-theme-ananke/issues"
},
"comments": {
"dependencies": {},
"devDependencies": {
"auto-changelog": "project",
"cssnano": "project",
"postcss-cli": "project",
"postcss-cssnext": "project",
"tachyons": "project"
}
},
"dependencies": {},
"description": "Theme Ananke",
"devDependencies": {
"auto-changelog": "^1.16.1",
"cssnano": "^3.10.0",
"postcss-cli": "^7.1.0",
"postcss-cssnext": "^2.10.0",
"tachyons": "^4.9.1"
},
"homepage": "https://github.com/theNewDynamic/gohugo-theme-ananke#readme",
"keywords": [
"hugo",
"gohugo"
],
"license": "MIT",
"main": "index.js",
"name": "gohugo-theme-ananke",
"repository": {
"type": "git",
"url": "git+https://github.com/theNewDynamic/gohugo-theme-ananke.git"
},
"scripts": {
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 && git add CHANGELOG.md"
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 \u0026\u0026 git add CHANGELOG.md"
},
"keywords": [
"hugo",
"gohugo"
],
"author": "budparr",
"license": "MIT",
"bugs": {
"url": "https://github.com/theNewDynamic/gohugo-theme-ananke/issues"
},
"homepage": "https://github.com/theNewDynamic/gohugo-theme-ananke#readme",
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"cssnano": "^3.10.0",
"postcss-cli": "^7.1.0",
"postcss-import": "^12.0.1",
"postcss-cssnext": "^2.10.0",
"tachyons": "^4.9.1",
"auto-changelog": "^1.16.1"
}
"version": "2.7.0"
}

View File

@ -7,27 +7,19 @@
"dependencies": {},
"devDependencies": {
"auto-changelog": "project",
"babel-core": "project",
"babel-loader": "project",
"babel-preset-env": "project",
"cssnano": "project",
"postcss-cli": "project",
"postcss-cssnext": "project",
"postcss-import": "project",
"tachyons": "project"
}
},
"dependencies": {},
"description": "Base Theme to start Hugo Sites",
"description": "Theme Ananke",
"devDependencies": {
"auto-changelog": "^1.16.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"cssnano": "^3.10.0",
"postcss-cli": "^7.1.0",
"postcss-cssnext": "^2.10.0",
"postcss-import": "^12.0.1",
"tachyons": "^4.9.1"
},
"homepage": "https://github.com/theNewDynamic/gohugo-theme-ananke#readme",
@ -43,7 +35,8 @@
"url": "git+https://github.com/theNewDynamic/gohugo-theme-ananke.git"
},
"scripts": {
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 \u0026\u0026 git add CHANGELOG.md"
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 \u0026\u0026 git add CHANGELOG.md",
"deploy": " cd exampleSite; hugo;"
},
"version": "2.7.0"
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"Target":"ananke/css/main.min.css","MediaType":"text/css","Data":{}}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
!function(n){function t(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};t.m=n,t.c=r,t.i=function(n){return n},t.d=function(n,r,e){t.o(n,r)||Object.defineProperty(n,r,{configurable:!1,enumerable:!0,get:e})},t.n=function(n){var r=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(r,"a",r),r},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=1)}([function(n,t){},function(n,t,r){"use strict";var e=r(0);!function(n){n&&n.__esModule}(e)}]);

View File

@ -8,7 +8,7 @@ description = "A Base theme for building full featured Hugo sites"
homepage = "https://github.com/theNewDynamic/gohugo-theme-ananke"
tags = ["website", "starter", "responsive", "Disqus", "blog", "Tachyons", "Multilingual", "Stackbit"]
features = ["posts", "shortcodes", "related content", "comments"]
min_version = "0.55.0"
min_version = "0.79.0"
[author]
name = "theNewDynamic"