1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-26 08:25:21 -04:00

add babel / esbuild pipes via Hugo, remove terser

This commit is contained in:
Jake Jarvis 2021-06-05 08:35:57 -04:00
parent 1a02c31a32
commit 23debefee2
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
18 changed files with 1965 additions and 218 deletions

View File

@ -4,12 +4,18 @@
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2015
"parser": "@babel/eslint-parser",
"ecmaVersion": 2018,
"sourceType": "script",
"babelOptions": {
"configFile": "./babel.config.json"
}
},
"env": {
"browser": true,
"es6": true
},
"rules": {},
"overrides": [{
"files": ["api/**/*.js"],
"parserOptions": {
@ -23,6 +29,5 @@
"compat/compat": "off"
}
}],
"rules": {},
"ignorePatterns": ["public/**"]
}

View File

@ -13,7 +13,7 @@ _vendor/
# dotfiles/config
.*
postcss.config.js
devcontainer.json
babel.config.json
# miscellaneous
vercel.json

View File

@ -1,15 +0,0 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"budparr.language-hugo-vscode",
"bungcip.better-toml",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"stylelint.vscode-stylelint"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}

31
.vscode/settings.json vendored
View File

@ -1,31 +0,0 @@
{
"editor.detectIndentation": true,
"editor.insertSpaces": true,
"editor.rulers": [
120
],
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.eol": "\n",
"files.insertFinalNewline": true,
"git.ignoreLimitWarning": true,
"npm.packageManager": "yarn",
"prettier.configPath": ".prettierrc",
"prettier.packageManager": "yarn",
"prettier.printWidth": 120,
"prettier.requireConfig": true,
"prettier.useEditorConfig": false,
"[markdown]": {
"editor.quickSuggestions": false,
"editor.trimAutoWhitespace": false,
"editor.wordWrap": "on"
},
"stylelint.packageManager": "yarn",
"stylelint.validate": [
"css",
"html",
"postcss",
"sass",
"scss"
]
}

3
assets/js/_bundle.js Normal file
View File

@ -0,0 +1,3 @@
require("./counter");
require("./projects");
require("./vendor/twemoji");

View File

@ -1,40 +1,37 @@
(function () {
// don't continue if there isn't a span#meta-hits element on this page
var wrapper = document.getElementById("meta-hits");
const fetch = require("node-fetch");
if (wrapper) {
// javascript is enabled so show the loading indicator
wrapper.style.display = "inline-block";
// don't continue if there isn't a span#meta-hits element on this page
const wrapper = document.getElementById("meta-hits");
// deduce a consistent identifier for this page, no matter the URL
var canonical = document.createElement("a");
canonical.href = document.querySelector("link[rel='canonical']").href;
if (wrapper) {
// javascript is enabled so show the loading indicator
wrapper.style.display = "inline-block";
// strip beginning and ending forward slash
var slug = canonical.pathname.slice(1, -1);
// deduce a consistent identifier for this page, no matter the URL
const canonical = document.createElement("a");
canonical.href = document.querySelector("link[rel='canonical']").href;
// this will return an error from the API anyways
if (!slug || slug === "/") return;
// strip beginning and ending forward slash
const slug = canonical.pathname.slice(1, -1);
fetch("/api/hits/?slug=" + slug)
.then((response) => response.json())
.then((data) => {
if (typeof data.hits !== "undefined") {
// finally inject the hits and hide the loading spinner
var spinner = document.getElementById("hit-spinner");
var counter = document.getElementById("hit-counter");
fetch("/api/hits/?slug=" + slug)
.then((response) => response.json())
.then((data) => {
if (typeof data.hits !== "undefined") {
// finally inject the hits and hide the loading spinner
const spinner = document.getElementById("hit-spinner");
const counter = document.getElementById("hit-counter");
spinner.style.display = "none";
wrapper.title = data.pretty_hits + " " + data.pretty_unit;
counter.appendChild(document.createTextNode(data.pretty_hits));
} else {
// something went horribly wrong, initiate coverup
wrapper.style.display = "none";
}
})
.catch((error) => {
spinner.style.display = "none";
wrapper.title = data.pretty_hits + " " + data.pretty_unit;
counter.appendChild(document.createTextNode(data.pretty_hits));
} else {
// something went horribly wrong, initiate coverup
wrapper.style.display = "none";
});
}
})();
}
})
.catch((error) => {
// something went horribly wrong, initiate coverup
wrapper.style.display = "none";
});
}

View File

@ -1,55 +1,54 @@
(function () {
// don't continue if there isn't a span#meta-hits element on this page
var wrapper = document.getElementById("github-cards");
const fetch = require("node-fetch");
if (wrapper) {
fetch("/api/projects/?top")
.then((response) => response.json())
.then((data) => {
data.forEach((repo) => {
var html = `
// don't continue if there isn't a span#meta-hits element on this page
const wrapper = document.getElementById("github-cards");
if (wrapper) {
fetch("/api/projects/?top")
.then((response) => response.json())
.then((data) => {
data.forEach((repo) => {
let html = `
<a class="repo-name" href="${repo.url}" target="_blank" rel="noopener">${repo.name}</a>
<p class="repo-description">${repo.description}</p>`;
if (repo.primaryLanguage !== null) {
html += `
<div class="repo-meta">
<span class="repo-language-color" style="background-color: ${repo.primaryLanguage.color}"></span>
<span>${repo.primaryLanguage.name}</span>
</div>`;
}
if (repo.stargazerCount > 0) {
html += `
<div class="repo-meta">
<svg viewBox="0 0 16 16" height="16" width="16"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
<span>${repo.stargazerCount_pretty}</span>
</div>`;
}
if (repo.forkCount > 0) {
html += `
<div class="repo-meta">
<svg viewBox="0 0 16 16" height="16" width="16"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
<span>${repo.forkCount_pretty}</span>
</div>`;
}
if (repo.primaryLanguage !== null) {
html += `
<div class="repo-meta">
<span title="${repo.pushedAt}">Updated ${repo.pushedAt_relative}</span>
<span class="repo-language-color" style="background-color: ${repo.primaryLanguage.color}"></span>
<span>${repo.primaryLanguage.name}</span>
</div>`;
}
if (repo.stargazerCount > 0) {
html += `
<div class="repo-meta">
<svg viewBox="0 0 16 16" height="16" width="16"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
<span>${repo.stargazerCount_pretty}</span>
</div>`;
}
if (repo.forkCount > 0) {
html += `
<div class="repo-meta">
<svg viewBox="0 0 16 16" height="16" width="16"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
<span>${repo.forkCount_pretty}</span>
</div>`;
}
html += `
<div class="repo-meta">
<span title="${repo.pushedAt}">Updated ${repo.pushedAt_relative}</span>
</div>`;
var div = document.createElement("div");
div.classList.add("github-card");
div.innerHTML = html;
wrapper.appendChild(div);
});
})
.catch((error) => {
// something went horribly wrong, initiate coverup
wrapper.style.display = "none";
console.error(error);
const div = document.createElement("div");
div.classList.add("github-card");
div.innerHTML = html;
wrapper.appendChild(div);
});
}
})();
})
.catch((error) => {
// something went horribly wrong, initiate coverup
wrapper.style.display = "none";
});
}

View File

@ -3,7 +3,7 @@
*/
(function () {
'use strict';
// 'use strict';
// the exported module object
var emoji = {

18
babel.config.json Normal file
View File

@ -0,0 +1,18 @@
{
"presets": [
[
"@babel/preset-env",
{
"include": ["transform-arrow-functions", "transform-block-scoping", "transform-template-literals"],
"useBuiltIns": "entry",
"corejs": 3
}
],
[
"minify",
{
"removeConsole": true
}
]
]
}

View File

@ -164,6 +164,7 @@ disableHugoGeneratorInject = true
dir = ":cacheDir/modules"
[build]
noJSConfigInAssets = true
writeStats = true
# don't use cache for SCSS compilation, better to throw error than be stale
useResourceCacheWhen = "never"

View File

@ -12,9 +12,11 @@
{{ block "main" . }}{{ end }}
</main>
{{ partial "page/footer" . }}
{{ partialCached "scripts/_bundle" . -}}
{{ template "__body_js" . }}
{{ partial "scripts/shortcodes" . -}}
</body>
</html>
{{ if ne hugo.Environment "production" }}
{{ partial "functions/debug" . }}
{{ end }}

View File

@ -1,3 +1,5 @@
{{ printf "<!-- htmlmin:ignore -->" | safeHTML -}}
{{ printf "<!-- %s -->" hugo.Environment | safeHTML }}
{{ printf "<!-- %s -->" hugo.Version | safeHTML }}
{{ printf "<!-- /content/%s -->" .File.Path | safeHTML }}
{{- printf "<!-- htmlmin:ignore -->" | safeHTML }}

View File

@ -1,3 +1,5 @@
{{- partial "scripts/_bundle" . -}}
{{/* Strip any markdown styling from page title for use in meta tags */}}
{{- with .Title -}}
{{- $.Scratch.Set "plainTitle" (. | markdownify | htmlUnescape | plainify) -}}

View File

@ -1,3 +1,4 @@
<link rel="preload" href="{{ "vendor/fonts/inter-subset.var.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "vendor/fonts/roboto-mono-subset.var.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "js/app.js" | absURL }}" as="script">
{{ template "__preload_js" . }}

View File

@ -1,11 +1,13 @@
{{- $counter := resources.Get "js/counter.js" -}}
{{- $projects := resources.Get "js/projects.js" -}}
{{- $twemoji := resources.Get "js/vendor/twemoji.js" -}}
{{ $js := resources.Get "js/_bundle.js" | js.Build (dict "targetPath" "/js/app.js") | resources.Babel (dict "config" "babel.config.json" "noComments" true) }}
{{- $bundle := slice $counter $projects $twemoji -}}
{{- $js := $bundle | resources.Concat "/js/app.js" -}}
{{- .Scratch.Set "bundlePermalink" $js.Permalink -}}
{{- define "__preload_js" -}}
<link rel="preload" href="{{ $.Scratch.Get "bundlePermalink" }}" as="script">
{{- end -}}
{{- define "__body_js" -}}
<!-- inline the dark mode script to avoid a blinding flash of white background on loads -->
<script>(function(d){var u=d.document,f=u.body.classList,e=localStorage,c="dark_mode_pref",t=e.getItem(c),a="dark",n="light",r="{{ .Site.Params.Theme.defaultTheme | safeJS }}",o=u.querySelector(".dark-mode-toggle"),i=r===a,b=function(d){f.remove(a,n);f.add(d);i=d===a};t===a&&b(a);t===n&&b(n);if(!t){var s=function(d){return"(prefers-color-scheme: "+d+")"};d.matchMedia(s(a)).matches?b(a):d.matchMedia(s(n)).matches?b(n):b(r);d.matchMedia(s(a)).addListener((function(d){d.matches&&b(a)}));d.matchMedia(s(n)).addListener((function(d){d.matches&&b(n)}))}if(o){o.style.display="block";o.addEventListener("click",(function(){if(i){b(n);e.setItem(c,n)}else{b(a);e.setItem(c,a)}}),!0)}})(window)</script>
<script async defer src="{{ $js.Permalink }}"></script>
<script async defer src="{{ $.Scratch.Get "bundlePermalink" }}"></script>
{{- end -}}

View File

@ -19,7 +19,6 @@
"build": "run-s build:** minify:**",
"build:hugo": "hugo --gc --cleanDestinationDir --verbose",
"minify:html": "html-minifier --html5 --collapse-whitespace --collapse-boolean-attributes --preserve-line-breaks --minify-css --remove-comments --file-ext html --input-dir public --output-dir public **/*.html",
"minify:js": "terser --compress passes=3,negate_iife=false,keep_fargs=false,sequences=false,reduce_vars=false --mangle reserved=['sa','sa_event'] --output public/js/app.js -- public/js/app.js",
"minify:img": "glob-exec --parallel --foreach 'public/**/{img,images}/' -- imagemin '{{file.path}}*' --plugin=mozjpeg --plugin.mozjpeg.progressive --plugin.mozjpeg.quality=85 --plugin=pngquant --plugin.pngquant.quality={0.1,0.3} --plugin.pngquant.speed=1 --plugin.pngquant.strip --plugin=gifsicle --plugin=svgo --out-dir='{{file.path}}'",
"lint": "run-s lint:**",
"lint:scss": "stylelint 'assets/sass/**/*.scss' --syntax scss",
@ -40,6 +39,7 @@
"html-escaper": "^3.0.3",
"luxon": "^1.27.0",
"modern-normalize": "1.1.0",
"node-fetch": "^2.6.1",
"numeral": "^2.0.6",
"pluralize": "^8.0.0",
"rss-parser": "^3.12.0",
@ -47,7 +47,12 @@
"twemoji-emojis": "13.1.0"
},
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.14.4",
"@babel/preset-env": "^7.14.4",
"autoprefixer": "^10.2.6",
"babel-minify": "^0.5.1",
"cross-env": "^7.0.3",
"eslint": "~7.28.0",
"eslint-config-prettier": "~8.3.0",
@ -55,7 +60,7 @@
"eslint-plugin-prettier": "~3.4.0",
"glob-exec": "^0.1.1",
"html-minifier": "^4.0.0",
"hugo-extended": "jakejarvis/hugo-extended#74fc0b50ee731a881d01e2908e31cbde84272629",
"hugo-extended": "jakejarvis/hugo-extended#9f615221831632cb3b8879ab3fc420fff921e1fd",
"imagemin-cli": "^6.0.0",
"lint-staged": "^11.0.0",
"markdownlint-cli": "~0.27.1",
@ -70,7 +75,7 @@
"postcss-normalize-charset": "^5.0.1",
"postcss-reporter": "^7.0.2",
"postcss-svgo": "^5.0.2",
"prettier": "^2.3.0",
"prettier": "^2.3.1",
"rimraf": "^3.0.2",
"simple-git-hooks": "^2.4.1",
"stylelint": "~13.13.1",
@ -78,8 +83,7 @@
"stylelint-config-sass-guidelines": "~8.0.0",
"stylelint-no-unsupported-browser-features": "~5.0.1",
"stylelint-prettier": "~1.2.0",
"stylelint-scss": "~3.19.0",
"terser": "^5.7.0"
"stylelint-scss": "~3.19.0"
},
"optionalDependencies": {
"imagemin-gifsicle": "^7.0.0",

View File

@ -63,6 +63,15 @@
}
]
},
{
"source": "/(img|js|css)/(.*)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=3600"
}
]
},
{
"source": "/pubkey.asc",
"headers": [

1900
yarn.lock

File diff suppressed because it is too large Load Diff