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

Feature: css cache busting #4177

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .github/workflows/pr-check-links.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
- name: Minify assets
run: |
cd sites/${{ matrix.site }}
npm run build:assets

- name: Check links in Markdown
run: |
Expand Down
2 changes: 0 additions & 2 deletions .platform/applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
npm install
npm run build
./build_docs.sh
npm run build:assets
deploy: |
cd $SITE_DIR
./deploy.sh
Expand Down Expand Up @@ -96,7 +95,6 @@
npm install
npm run build
./build_docs.sh
npm run build:assets
deploy: |
cd $SITE_DIR
./deploy.sh
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ To ensure the docs work smoothly, a few checks run on each pull request:
npm run build:search
# Build HTML pages to check
hugo
# Build production JavaScript and CSS files
npm run build:assets
# Run the check
./bin/htmltest
```
Expand Down
5 changes: 2 additions & 3 deletions build_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ clean_file () {
echo "$FILE exists. Removing..."
rm $FILE
echo "Done."
else
else
echo "$FILE does not exist. All is well."
fi
}
Expand All @@ -36,7 +36,6 @@ npm install
npm run build
npm run build:search
hugo
npm run build:assets

clear

Expand All @@ -49,4 +48,4 @@ Verify the resulting build by running the command

python3 -m http.server 8888 -d sites/$BUILD_DIR/public

"
"
43 changes: 36 additions & 7 deletions sites/platform/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 sites/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"author": "Platform.sh",
"scripts": {
"build": "npm run fetch-files && npm run registry-files",
"build:assets": "postcss --use cssnano --no-map --output 'public/asciinema/asciinema-player-mini.css' 'public/asciinema/asciinema-player.css' && postcss --use cssnano --no-map --output 'public/css/main-mini.css' 'public/css/main.css' && postcss --use cssnano --no-map --output 'public/css/syntax-highlighting-mini.css' 'public/css/syntax-highlighting.css' && postcss --use cssnano --no-map --output 'public/css/vendor-mini.css' 'public/css/vendor.css'",
"build:search": "npm run build --workspace docs-search-input",
"dev": "npm run fetch-files && npm run registry-files",
"fetch-files": "node utils/fetch-examples.mjs && node utils/fetchTemplates.mjs",
Expand All @@ -28,6 +27,7 @@
"p-limit": "^4.0.0",
"postcss": "^8.4.31",
"postcss-cli": "^10.1.0",
"postcss-import": "^16.1.0",
"pshregistry-parser": "^1.5.7",
"remark": "^14.0.2",
"remark-cli": "^11.0.0",
Expand Down
43 changes: 36 additions & 7 deletions sites/upsun/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 sites/upsun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"author": "Platform.sh",
"scripts": {
"build": "npm run fetch-files && npm run registry-files",
"build:assets": "postcss --use cssnano --no-map --output 'public/asciinema/asciinema-player-mini.css' 'public/asciinema/asciinema-player.css' && postcss --use cssnano --no-map --output 'public/css/main-mini.css' 'public/css/main.css' && postcss --use cssnano --no-map --output 'public/css/syntax-highlighting-mini.css' 'public/css/syntax-highlighting.css' && postcss --use cssnano --no-map --output 'public/css/vendor-mini.css' 'public/css/vendor.css'",
"build:search": "npm run build --workspace docs-search-input",
"dev": "npm run fetch-files && npm run registry-files",
"fetch-files": "node utils/fetch-examples.mjs && node utils/fetchTemplates.mjs",
Expand All @@ -26,6 +25,7 @@
"p-limit": "^4.0.0",
"postcss": "^8.4.31",
"postcss-cli": "^10.1.0",
"postcss-import": "^16.1.0",
"pshregistry-parser": "^1.5.7",
"remark": "^14.0.2",
"remark-cli": "^11.0.0",
Expand Down
9 changes: 3 additions & 6 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ npm run build:search
# 3. Build Hugo site
hugo

# 4. Minify assets
npm run build:assets

# 5. Check links in Markdown
# 4. Check links in Markdown
curl https://htmltest.wjdp.uk | bash
bin/htmltest

# 6. Linting (Lint markdown)
# 5. Linting (Lint markdown)
npm run lint:markdown

# 7. Linting (Lint prose)
# 6. Linting (Lint prose)
vale src
2 changes: 2 additions & 0 deletions themes/psh-docs/assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Relative to site directory */
@import './node_modules/asciinema-player/dist/bundle/asciinema-player.css';
/* Base TailwindCSS styles */
/* https://tailwindcss.com/docs/functions-and-directives#tailwind */

Expand Down
27 changes: 10 additions & 17 deletions themes/psh-docs/layouts/partials/head/css.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
{{ $productionSuffix := "" }}
{{ if hugo.IsProduction }}
{{ $productionSuffix = "-mini" }}
{{ end }}

<!-- stylesheets using `minify` will be minified in production -->
<!-- Vendor overrides -->
{{ if eq .Site.Params.theme.use_vendor true }}
<link rel="stylesheet" href="{{ printf "/css/vendor%s.css?version=%s" $productionSuffix $.Site.Params.version }}">
{{ $vendorCSS := resources.Get "css/vendor.css" | postCSS | fingerprint }}
<link rel="stylesheet" href="{{ printf "%s?version=%s" $vendorCSS.RelPermalink $.Site.Params.version }}">
{{ end }}


<!-- Asciinema player -->
<link rel="stylesheet" href="{{ printf "/asciinema/asciinema-player%s.css?version=%s" $productionSuffix $.Site.Params.version }}">
<!-- Asciinema player: moved to tailwind config.css -->

<!-- Syntax highlighting -->
<link rel="stylesheet" href="{{ printf "/css/syntax-highlighting%s.css?version=%s" $productionSuffix $.Site.Params.version }}">
{{ $syntaxHighlightingCSS := resources.Get "css/vendor.css" | postCSS | fingerprint }}
<link rel="stylesheet" href="{{ printf "%s?version=%s" $syntaxHighlightingCSS.RelPermalink $.Site.Params.version }}">

<!-- TailwindCSS files -->
{{ $style := resources.Get "css/main.css" | resources.PostCSS }}
{{ $style = $style.RelPermalink }}
{{ if hugo.IsProduction }}
{{ $style = "/css/main-mini.css" }}
{{ end }}
<link rel="stylesheet" href="{{ printf "%s?version=%s" $style $.Site.Params.version }}">
{{ $mainStyle := resources.Get "css/main.css" | postCSS | fingerprint }}
<link rel="stylesheet" href="{{ printf "%s?version=%s" $mainStyle.RelPermalink $.Site.Params.version }}">

<!-- Print stylesheets -->
{{ with .File }}
{{- if eq .Dir "security/transparency/" -}}
<link rel="stylesheet" media="print" href="{{ printf "styles/print/transparency-reports.css?version=%s" $.Site.Params.version | relURL}}">
{{ $transparencyReportsCSS := resources.Get "css/print/transparency-reports.css" | postCSS | fingerprint }}
<link rel="stylesheet" href="{{ printf "%s?version=%s" $transparencyReportsCSS.RelPermalink $.Site.Params.version }}">
{{- end -}}
{{ end }}
13 changes: 12 additions & 1 deletion themes/psh-docs/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ const themeDir = '../../themes';

module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss')(themeDir + '/psh-docs/tailwind.config.js'),
require('autoprefixer')({
path: [themeDir]
}),
...process.env.HUGO_ENVIRONMENT === 'production'
? [
require('cssnano')({
preset: ['default', {
discardComments: { removeAll: true }, // Ensure all comments are removed
normalizeWhitespace: true, // Ensures that whitespace is minimized
}]
})
]
: []
]
}
}
2 changes: 1 addition & 1 deletion themes/psh-docs/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ module.exports = {
plugins: [
require("@tailwindcss/typography"),
],
}
}
Loading