1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-10-28 15:35:50 -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

View File

@@ -10,5 +10,12 @@
"browser": true,
"es6": true
},
"overrides": [{
"files": ["functions/**.js"],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
}
}],
"rules": {}
}

View File

@@ -96,7 +96,7 @@ jobs:
run: yarn lint
continue-on-error: true
- name: Build
run: yarn build:preview
run: yarn build:hugo --environment development --baseURL / --buildDrafts --buildFuture
- name: Percy snapshots
# don't run for all of dependabot's PRs -- I'm using the free plan...
if: "!contains(github.actor, '[bot]')"

View File

@@ -1,5 +1,6 @@
# Hugo stuff that doesn't play well with Prettier
assets/**/vendor/
data/
layouts/
static/

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
### 🧶  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:
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
docker run --rm -v $(pwd):/src -p 1337:1337 $(docker build --no-cache -q .)

View File

@@ -384,4 +384,4 @@
} catch (e) {
console.warn(e);
}
})(window, "{{ (urls.Parse .Site.BaseURL).Host }}/sa");
})(window, "{{ (urls.Parse .Site.BaseURL).Host }}/api/views");

View File

@@ -166,3 +166,8 @@ disableAliases = true
for = "/**"
[server.headers.values]
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
functions/hello.js Normal file
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)}`,
}),
};
}

View File

@@ -297,7 +297,7 @@
{{ if eq hugo.Environment "production" }}
<!-- 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 }}
</body>
</html>

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-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/hack/hack-regular-subset.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>

View File

@@ -3,7 +3,7 @@ User-Agent: *
Allow: /.well-known/amphtml/apikey.pub
Disallow: /403.html
Disallow: /404.html
Disallow: /sa/
Disallow: /api/
Disallow: /y2k/
Sitemap: {{ "sitemap.xml" | absURL }}
{{- else }}

View File

@@ -1,6 +1,7 @@
[build]
command = "yarn build"
publish = "public"
functions = ".netlify/functions"
[build.environment]
YARN_VERSION = "1.22.4"
@@ -23,19 +24,17 @@
compress = false
[context.deploy-preview]
command = "yarn build:preview"
# ignore = "git log -1 --pretty=format:'%an' | grep 'dependabot'"
command = "yarn build:hugo --environment development --baseURL $DEPLOY_PRIME_URL --buildDrafts --buildFuture"
[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
[dev]
framework = "#custom"
command = "yarn start --baseURL=/ --appendPort=false --disableLiveReload"
port = 1338
command = "yarn start:hugo --baseURL=/ --appendPort=false --disableLiveReload"
targetPort = 1337
publish = "public"
port = 1338
autoLaunch = false
# Cache resoures between builds:
@@ -118,19 +117,32 @@
# Proxy data to Simple Analytics endpoints:
[[redirects]]
from = "/sa/send*"
from = "/api/views/send*"
to = "https://queue.simpleanalyticscdn.com/simple.gif:splat"
status = 200
force = true
[[redirects]]
from = "/sa/append*"
from = "/api/views/append*"
to = "https://queue.simpleanalyticscdn.com/append:splat"
status = 200
force = true
[[redirects]]
# This noscript pixel needs to pass unknown arguments along for AMP pages:
# https://amp.dev/documentation/components/amp-pixel/
from = "/sa/noscript.gif*"
from = "/api/views/noscript.gif*"
to = "https://queue.simpleanalyticscdn.com/noscript.gif:splat"
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:
[[redirects]]

View File

@@ -14,25 +14,24 @@
"url": "git+https://github.com/jakejarvis/jarv.is.git"
},
"scripts": {
"clean": "hugo mod clean && rimraf public/ resources/ builds/ _vendor/ $TMPDIR/hugo_cache/ || true",
"build": "run-s hugo:vendor hugo minify",
"build:preview": "run-s hugo:vendor hugo:preview",
"hugo": "hugo --gc --cleanDestinationDir --verbose",
"hugo:preview": "hugo --environment development --baseURL ${DEPLOY_PRIME_URL:-/} --buildDrafts --buildFuture --gc --cleanDestinationDir --verbose",
"hugo:vendor": "hugo mod vendor",
"start": "hugo server --disableFastRender --buildDrafts --buildFuture --port 1337 --bind 0.0.0.0 --verbose",
"clean": "hugo mod clean && rimraf public/ resources/ builds/ _vendor/ .netlify/functions/ $TMPDIR/hugo_cache/ || true",
"build": "run-s build:** minify",
"build:hugo": "hugo --gc --cleanDestinationDir --verbose",
"build:functions": "netlify-lambda build functions",
"start": "run-p start:hugo",
"start:hugo": "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:live": "netlify dev --live",
"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: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='{}'",
"lint": "run-s lint:**",
"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:prettier": "prettier --check .",
"index": "run-s clean hugo index:**",
"index": "run-s clean build:hugo index:**",
"index:algolia": "npx atomic-algolia"
},
"dependencies": {
@@ -58,6 +57,7 @@
"imagemin-svgo": "^8.0.0",
"lint-staged": "^10.2.11",
"markdownlint-cli": "~0.23.2",
"netlify-lambda": "^1.6.3",
"netlify-plugin-cache": "*",
"netlify-plugin-debug-cache": "*",
"npm-run-all": "^4.1.5",

3042
yarn.lock

File diff suppressed because it is too large Load Diff