Skip to content

Commit

Permalink
Dynamicallly generated redirects instead of copying to lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Jul 15, 2024
1 parent 7127438 commit 7d8852d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ index.html
api/
!backends/github/api/
!backends/coda/api/
lib
_redirects
10 changes: 10 additions & 0 deletions _build/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import packageLock from "../package-lock.json" with { type: "json" };

export function relative (page) {
if (!page) {
Expand All @@ -10,4 +11,13 @@ export function relative (page) {
let ret = path.relative(pagePath, "/");

return ret || ".";
}

/**
* Convert a package.json dependency version to
* @param {*} semver
* @returns
*/
export function version (module) {
return packageLock.packages[`node_modules/${module}`]?.version;
}
28 changes: 0 additions & 28 deletions _build/lib.mjs

This file was deleted.

12 changes: 12 additions & 0 deletions _redirects.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
permalink: _redirects
layout: null
eleventyExcludeFromCollections: true
---

{% for module, version in pkg.dependencies -%}
node_modules/{{ module }}/* https://cdn.jsdelivr.net/npm/{{ module }}@{{ (module | version) or "latest" }}/:splat 200
{% endfor %}

# Catch all NPM fallback
node_modules/:modulename/* https://cdn.jsdelivr.net/npm/:modulename@latest/:splat 200
2 changes: 1 addition & 1 deletion formats/csv/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Format from "../../src/format.js";
import { parse, stringify } from "../../lib/csv/dist/esm/sync.js";
import { parse, stringify } from "../../node_modules/csv/dist/esm/sync.js";

export default class CSV extends Format {
static defaultOptions = {
Expand Down
2 changes: 1 addition & 1 deletion formats/yaml/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Format from "../../src/format.js";
import { parse, stringify } from "../../lib/yaml/browser/index.js";
import { parse, stringify } from "../../node_modules/yaml/browser/index.js";

export default class YAML extends Format {
static extensions = ["yaml", "yml"];
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"scripts": {
"test": "npx htest test/index.js",
"build:html": "npx @11ty/eleventy --config=_build/eleventy.js",
"build:lib": "node _build/lib.mjs",
"build:docs": "npx typedoc",
"build": "npm run build:lib && npm run build:html && npm run build:docs",
"build": "npm run build:html && npm run build:docs",
"watch:html": "npx @11ty/eleventy --config=_build/eleventy.js --watch",
"watch:docs": "npx typedoc --watch --preserveWatchOutput",
"watch": "npx concurrently -n w: npm:watch:*",
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function phrase (me, id, ...args) {
return id + " " + args.join(" ");
}

export const URLPattern = globalThis.URLPattern ?? (await import("../lib/urlpattern-polyfill/index.js")).URLPattern;
export const URLPattern = globalThis.URLPattern ?? (await import("../node_modules/urlpattern-polyfill/index.js")).URLPattern;

export function testURLs (source, urls) {
if (!urls) {
Expand Down

0 comments on commit 7d8852d

Please sign in to comment.