1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-05-17 21:04:25 -04:00

make sure config for Netlify functions is okay so far 😬

[skip ci]
This commit is contained in:
2020-07-10 20:00:39 -04:00
parent 78001a69d5
commit 725c482ba3
13 changed files with 3062 additions and 70 deletions
+7
View File
@@ -10,5 +10,12 @@
"browser": true, "browser": true,
"es6": true "es6": true
}, },
"overrides": [{
"files": ["functions/**.js"],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
}
}],
"rules": {} "rules": {}
} }
+1 -1
View File
@@ -96,7 +96,7 @@ jobs:
run: yarn lint run: yarn lint
continue-on-error: true continue-on-error: true
- name: Build - name: Build
run: yarn build:preview run: yarn build:hugo --environment development --baseURL / --buildDrafts --buildFuture
- name: Percy snapshots - name: Percy snapshots
# don't run for all of dependabot's PRs -- I'm using the free plan... # don't run for all of dependabot's PRs -- I'm using the free plan...
if: "!contains(github.actor, '[bot]')" if: "!contains(github.actor, '[bot]')"
+1
View File
@@ -1,5 +1,6 @@
# Hugo stuff that doesn't play well with Prettier # Hugo stuff that doesn't play well with Prettier
assets/**/vendor/ assets/**/vendor/
data/
layouts/ layouts/
static/ static/
+3 -3
View File
@@ -18,15 +18,15 @@ I keep an ongoing list of [blog post ideas](https://github.com/jakejarvis/jarv.i
## 💾  Running a local testing server ## 💾  Running a local testing server
### 🧶  Using Yarn/NPM: ### 🧶  Using Yarn:
Run `yarn install` ([Yarn must be installed](https://yarnpkg.com/en/docs/install) first, or use `npm install` if you insist) and `yarn start` (or `npm start`), then open [http://localhost:1337/](http://localhost:1337/). Pages will live-refresh when source files are changed. Run `yarn install` ([Yarn must be installed](https://yarnpkg.com/en/docs/install) first; NPM _should_ work at your own risk) and `yarn start`, then open [http://localhost:1337/](http://localhost:1337/). Pages will live-refresh when source files are changed.
### 🐳  Using Docker: ### 🐳  Using Docker:
To ensure consistency and compatibility, the [`Dockerfile`](Dockerfile) in this repository will download the correct version of the Hugo Extended binary and its dependencies, and start a live testing server in a temporary container. To ensure consistency and compatibility, the [`Dockerfile`](Dockerfile) in this repository will download the correct version of the Hugo Extended binary and its dependencies, and start a live testing server in a temporary container.
Using Docker doesn't require Node or Yarn, but you can also use `yarn start:docker` (or `npm run start:docker`) which is simply an alias for: Using Docker doesn't require Node or Yarn, but you can also use `yarn start:docker` which is simply an alias for:
```bash ```bash
docker run --rm -v $(pwd):/src -p 1337:1337 $(docker build --no-cache -q .) docker run --rm -v $(pwd):/src -p 1337:1337 $(docker build --no-cache -q .)
+1 -1
View File
@@ -384,4 +384,4 @@
} catch (e) { } catch (e) {
console.warn(e); console.warn(e);
} }
})(window, "{{ (urls.Parse .Site.BaseURL).Host }}/sa"); })(window, "{{ (urls.Parse .Site.BaseURL).Host }}/api/views");
+5
View File
@@ -166,3 +166,8 @@ disableAliases = true
for = "/**" for = "/**"
[server.headers.values] [server.headers.values]
Access-Control-Allow-Origin = "*" Access-Control-Allow-Origin = "*"
# TODO: Proxy /api requests to netlify-lambda's local server for each function
[[server.redirects]]
from = "/api/**"
to = "http://localhost:9000/"
status = 200
+12
View File
@@ -0,0 +1,12 @@
export async function handler(event, context, callback) {
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: "Hello from the other side...",
lucky_num: `${Math.floor(Math.random() * 100)}`,
}),
};
}
+1 -1
View File
@@ -297,7 +297,7 @@
{{ if eq hugo.Environment "production" }} {{ if eq hugo.Environment "production" }}
<!-- https://docs.simpleanalytics.com/without-javascript --> <!-- https://docs.simpleanalytics.com/without-javascript -->
<amp-pixel src="{{ "sa/noscript.gif" | absURL }}?ignore-dnt=true&hostname=CANONICAL_HOSTNAME&path=CANONICAL_PATH&referrer=DOCUMENT_REFERRER&https=true&ua=USER_AGENT&width=VIEWPORT_WIDTH&type=pageview" layout="nodisplay"></amp-pixel> <amp-pixel src="{{ "api/views/noscript.gif" | absURL }}?ignore-dnt=true&hostname=CANONICAL_HOSTNAME&path=CANONICAL_PATH&referrer=DOCUMENT_REFERRER&https=true&ua=USER_AGENT&width=VIEWPORT_WIDTH&type=pageview" layout="nodisplay"></amp-pixel>
{{ end }} {{ end }}
</body> </body>
</html> </html>
+1
View File
@@ -1,3 +1,4 @@
<link rel="preload" href="{{ "vendor/inter/inter-regular-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin> <link rel="preload" href="{{ "vendor/inter/inter-regular-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "vendor/inter/inter-medium-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin> <link rel="preload" href="{{ "vendor/inter/inter-medium-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "vendor/inter/inter-bold-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin> <link rel="preload" href="{{ "vendor/inter/inter-bold-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "vendor/hack/hack-regular-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
+1 -1
View File
@@ -3,7 +3,7 @@ User-Agent: *
Allow: /.well-known/amphtml/apikey.pub Allow: /.well-known/amphtml/apikey.pub
Disallow: /403.html Disallow: /403.html
Disallow: /404.html Disallow: /404.html
Disallow: /sa/ Disallow: /api/
Disallow: /y2k/ Disallow: /y2k/
Sitemap: {{ "sitemap.xml" | absURL }} Sitemap: {{ "sitemap.xml" | absURL }}
{{- else }} {{- else }}
+21 -9
View File
@@ -1,6 +1,7 @@
[build] [build]
command = "yarn build" command = "yarn build"
publish = "public" publish = "public"
functions = ".netlify/functions"
[build.environment] [build.environment]
YARN_VERSION = "1.22.4" YARN_VERSION = "1.22.4"
@@ -23,19 +24,17 @@
compress = false compress = false
[context.deploy-preview] [context.deploy-preview]
command = "yarn build:preview" command = "yarn build:hugo --environment development --baseURL $DEPLOY_PRIME_URL --buildDrafts --buildFuture"
# ignore = "git log -1 --pretty=format:'%an' | grep 'dependabot'"
[context.branch-deploy] [context.branch-deploy]
command = "yarn build:preview" command = "yarn build:hugo --environment development --baseURL $DEPLOY_PRIME_URL --buildDrafts --buildFuture"
# https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#netlifytoml-dev-block # https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#netlifytoml-dev-block
[dev] [dev]
framework = "#custom" framework = "#custom"
command = "yarn start --baseURL=/ --appendPort=false --disableLiveReload" command = "yarn start:hugo --baseURL=/ --appendPort=false --disableLiveReload"
port = 1338
targetPort = 1337 targetPort = 1337
publish = "public" port = 1338
autoLaunch = false autoLaunch = false
# Cache resoures between builds: # Cache resoures between builds:
@@ -118,19 +117,32 @@
# Proxy data to Simple Analytics endpoints: # Proxy data to Simple Analytics endpoints:
[[redirects]] [[redirects]]
from = "/sa/send*" from = "/api/views/send*"
to = "https://queue.simpleanalyticscdn.com/simple.gif:splat" to = "https://queue.simpleanalyticscdn.com/simple.gif:splat"
status = 200 status = 200
force = true
[[redirects]] [[redirects]]
from = "/sa/append*" from = "/api/views/append*"
to = "https://queue.simpleanalyticscdn.com/append:splat" to = "https://queue.simpleanalyticscdn.com/append:splat"
status = 200 status = 200
force = true
[[redirects]] [[redirects]]
# This noscript pixel needs to pass unknown arguments along for AMP pages: # This noscript pixel needs to pass unknown arguments along for AMP pages:
# https://amp.dev/documentation/components/amp-pixel/ # https://amp.dev/documentation/components/amp-pixel/
from = "/sa/noscript.gif*" from = "/api/views/noscript.gif*"
to = "https://queue.simpleanalyticscdn.com/noscript.gif:splat" to = "https://queue.simpleanalyticscdn.com/noscript.gif:splat"
status = 200 status = 200
force = true
# TEMPORARY: Moved analytics endpoints above into /api/views
[[redirects]]
from = "/sa/*"
to = "/api/views/:splat"
status = 301
# Prettier URLs for Netlify Functions (must come after /api/views rules above)
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
# More miscellaneous mirrors/redirects: # More miscellaneous mirrors/redirects:
[[redirects]] [[redirects]]
+10 -10
View File
@@ -14,25 +14,24 @@
"url": "git+https://github.com/jakejarvis/jarv.is.git" "url": "git+https://github.com/jakejarvis/jarv.is.git"
}, },
"scripts": { "scripts": {
"clean": "hugo mod clean && rimraf public/ resources/ builds/ _vendor/ $TMPDIR/hugo_cache/ || true", "clean": "hugo mod clean && rimraf public/ resources/ builds/ _vendor/ .netlify/functions/ $TMPDIR/hugo_cache/ || true",
"build": "run-s hugo:vendor hugo minify", "build": "run-s build:** minify",
"build:preview": "run-s hugo:vendor hugo:preview", "build:hugo": "hugo --gc --cleanDestinationDir --verbose",
"hugo": "hugo --gc --cleanDestinationDir --verbose", "build:functions": "netlify-lambda build functions",
"hugo:preview": "hugo --environment development --baseURL ${DEPLOY_PRIME_URL:-/} --buildDrafts --buildFuture --gc --cleanDestinationDir --verbose", "start": "run-p start:hugo",
"hugo:vendor": "hugo mod vendor", "start:hugo": "hugo server --disableFastRender --buildDrafts --buildFuture --port 1337 --bind 0.0.0.0 --verbose",
"start": "hugo server --disableFastRender --buildDrafts --buildFuture --port 1337 --bind 0.0.0.0 --verbose", "start:netlify": "netlify dev --live",
"start:docker": "docker run --rm -v $(pwd):/src -p 1337:1337 $(docker build --no-cache -q .)", "start:docker": "docker run --rm -v $(pwd):/src -p 1337:1337 $(docker build --no-cache -q .)",
"start:live": "netlify dev --live",
"minify": "run-p minify:**", "minify": "run-p minify:**",
"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: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: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": "find './public' -type d ! -path './public/vendor*' | xargs -n1 -P8 -I{} imagemin '{}/*' --plugin=jpegoptim --plugin.jpegoptim.progressive --plugin.jpegoptim.stripAll --plugin=pngquant --plugin.pngquant.quality={0.1,0.3} --plugin.pngquant.speed=1 --plugin.pngquant.strip --plugin=gifsicle --plugin=svgo --out-dir='{}'", "minify:img": "find './public' -type d ! -path './public/vendor*' | xargs -n1 -P8 -I{} imagemin '{}/*' --plugin=jpegoptim --plugin.jpegoptim.progressive --plugin.jpegoptim.stripAll --plugin=pngquant --plugin.pngquant.quality={0.1,0.3} --plugin.pngquant.speed=1 --plugin.pngquant.strip --plugin=gifsicle --plugin=svgo --out-dir='{}'",
"lint": "run-s lint:**", "lint": "run-s lint:**",
"lint:scss": "stylelint 'assets/sass/**/*.scss' --syntax scss", "lint:scss": "stylelint 'assets/sass/**/*.scss' --syntax scss",
"lint:js": "eslint 'assets/js/**/*.js'", "lint:js": "eslint 'assets/js/**/*.js' 'functions/**/*.js'",
"lint:md": "markdownlint 'content/**/*.md'", "lint:md": "markdownlint 'content/**/*.md'",
"lint:prettier": "prettier --check .", "lint:prettier": "prettier --check .",
"index": "run-s clean hugo index:**", "index": "run-s clean build:hugo index:**",
"index:algolia": "npx atomic-algolia" "index:algolia": "npx atomic-algolia"
}, },
"dependencies": { "dependencies": {
@@ -58,6 +57,7 @@
"imagemin-svgo": "^8.0.0", "imagemin-svgo": "^8.0.0",
"lint-staged": "^10.2.11", "lint-staged": "^10.2.11",
"markdownlint-cli": "~0.23.2", "markdownlint-cli": "~0.23.2",
"netlify-lambda": "^1.6.3",
"netlify-plugin-cache": "*", "netlify-plugin-cache": "*",
"netlify-plugin-debug-cache": "*", "netlify-plugin-debug-cache": "*",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
+2998 -44
View File
File diff suppressed because it is too large Load Diff