feat(environment): use hugo.Environment to judge the production environment

This commit is contained in:
Dillon 2020-03-02 17:03:35 +08:00
parent f83b1c14c8
commit 285efc01bb
5 changed files with 3 additions and 19 deletions

View file

@ -8,7 +8,7 @@ jobs:
- checkout - checkout
- run: git submodule sync - run: git submodule sync
- run: git submodule update --init - run: git submodule update --init
- run: HUGO_ENV=production hugo --source=exampleSite -v --gc - run: hugo --source=exampleSite -v --gc
- run: htmlproofer exampleSite/public --check-html --allow-hash-href --empty-alt-ignore --disable-external - run: htmlproofer exampleSite/public --check-html --allow-hash-href --empty-alt-ignore --disable-external
workflows: workflows:

View file

@ -158,14 +158,6 @@ Customize `browserconfig.xml` and `site.webmanifest` to set theme-color and back
## Tips ## Tips
### Set `production` environment when generating site
Because some features are only in production mode, so you need to add a `production` environment variables when generating your site.
```bash
HUGO_ENV=production hugo --gc --minify
```
### How to toggle dark-light mode ### How to toggle dark-light mode
* You can click the circle icon to toggle dark-light mode. In the desktop version the circle icon is to the right and in the mobile version is positioned to the left, close to the site title. * You can click the circle icon to toggle dark-light mode. In the desktop version the circle icon is to the right and in the mobile version is positioned to the left, close to the site title.

View file

@ -153,14 +153,6 @@
## 小技巧 ## 小技巧
### 在生成网站时设置 `production` 环境变量
由于主题的一些功能仅在生产环境有效,所以你需要在生成网站时设置 `production` 环境变量。
```bash
HUGO_ENV=production hugo --gc --minify
```
### 怎样切换网站 暗黑-明亮 模式 ### 怎样切换网站 暗黑-明亮 模式
* 你可以点击圆形图标来切换网站 暗黑-明亮 模式。桌面模式下圆形图标在网页右上角,移动设备模式下在网站左上角标题旁边 * 你可以点击圆形图标来切换网站 暗黑-明亮 模式。桌面模式下圆形图标在网页右上角,移动设备模式下在网站左上角标题旁边

View file

@ -5,7 +5,7 @@
{{- $scratch := newScratch -}} {{- $scratch := newScratch -}}
{{- .Scratch.Set "scratch" $scratch -}} {{- .Scratch.Set "scratch" $scratch -}}
{{- if eq (getenv "HUGO_ENV") "production" -}} {{- if eq hugo.Environment "production" -}}
{{- $scratch.Set "production" true -}} {{- $scratch.Set "production" true -}}
{{- $scratch.Set "CDN" .Site.Params.cdn -}} {{- $scratch.Set "CDN" .Site.Params.cdn -}}
{{- end -}} {{- end -}}

View file

@ -14,7 +14,7 @@
"scripts": { "scripts": {
"build": "npx babel src --out-file assets/js/theme.min.js --source-maps", "build": "npx babel src --out-file assets/js/theme.min.js --source-maps",
"start": "hugo server --source=exampleSite --themesDir=../.. --disableFastRender -D", "start": "hugo server --source=exampleSite --themesDir=../.. --disableFastRender -D",
"copy": "HUGO_ENV=production hugo -v --source=exampleSite --themesDir=../.. -D --gc --minify && rm -rf resources && cp -rf exampleSite/resources resources" "copy": "hugo -v --source=exampleSite --themesDir=../.. -D --gc --minify && rm -rf resources && cp -rf exampleSite/resources resources"
}, },
"husky": { "husky": {
"hooks": { "hooks": {