Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 9, 2024
1 parent e0ea07b commit 76a600f
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 91 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Node Unit Tests
on:
push:
branches-ignore:
- "gh-pages"
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
node: ["18", "20"]
name: Node.js ${{ matrix.node }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
# cache: npm
- run: npm install
- run: npm test
env:
YARN_GPG: no
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

74 changes: 29 additions & 45 deletions lib/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,36 @@
const HTTP_EQUIV = "http-equiv";
const REFRESH = "refresh";

const isHttpEquiv = ({attrs}) => HTTP_EQUIV in attrs && attrs[HTTP_EQUIV].toLowerCase()===REFRESH;



const DEFAULT_OPTIONS =
{
filter:
{
"*": { itemtype:true },
a: { href:true, ping:true },
applet: { archive:true, code:true, codebase:true, object:true, src:true },
area: { href:true, ping:true },
audio: { src:true },
base: { href:true },
blockquote: { cite:true },
body: { background:true },
button: { formaction:true },
del: { cite:true },
embed: { src:true },
form: { action:true },
frame: { longdesc:true, src:true },
head: { profile:true },
html: { manifest:true },
iframe: { longdesc:true, src:true },
img: { longdesc:true, src:true, srcset:true },
input: { formaction:true, src:true },
ins: { cite:true },
link: { href:true },
menuitem: { icon:true },
meta: { content:isHttpEquiv },
object: { codebase:true, data:true },
q: { cite:true },
script: { src:true },
source: { src:true, srcset:true },
table: { background:true },
tbody: { background:true },
td: { background:true },
tfoot: { background:true },
th: { background:true },
thead: { background:true },
tr: { background:true },
track: { src:true },
video: { poster:true, src:true }
}
const isHttpEquiv = ({ attrs }) => {
return attrs && (HTTP_EQUIV in attrs) && attrs[HTTP_EQUIV].toLowerCase() === REFRESH;
};


// Fork: pruned some deprecated tag/attribute combos here.
const DEFAULT_OPTIONS = {
filter: {
a: { href: true, ping: true },
area: { href: true, ping: true },
audio: { src: true },
base: { href: true },
blockquote: { cite: true },
button: { formaction: true },
del: { cite: true },
embed: { src: true },
form: { action: true },
iframe: { src: true },
img: { src: true, srcset: true },
input: { formaction: true, src: true },
ins: { cite: true },
link: { href: true },
meta: { content: isHttpEquiv },
object: { data: true },
q: { cite: true },
script: { src: true },
source: { src: true, srcset: true },
track: { src: true },
// video does not yet have srcset: https://scottjehl.com/posts/using-responsive-video/
video: { poster: true, src: true },
},
};

module.exports = DEFAULT_OPTIONS;
61 changes: 31 additions & 30 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,52 @@ const plugin = options =>
throw new TypeError("eachURL option must be a function");
}

const allTagsGroup = filter["*"];
// const tagMatchers = Object.keys(filter).map(tagName => ({ tag: tagName }));

// Called by PostHTML
return tree =>
{
const promises = [];

tree.walk(node =>
// tree.match(tagMatchers, (node) =>
{
if (node.attrs !== undefined)
if (node.attrs === undefined) {
return node;
}

const tagGroup = filter[node.tag] || EMPTY_TAG_GROUP;

Object.keys(node.attrs).forEach(attrName =>
{
const tagGroup = filter[node.tag] || EMPTY_TAG_GROUP;
const isAcceptedTagAttr = attrName in tagGroup && evaluateValue(tagGroup[attrName], node, attrName);

Object.keys(node.attrs).forEach(attrName =>
if (isAcceptedTagAttr)
{
const isAcceptedGlobalAttr = attrName in allTagsGroup && evaluateValue(allTagsGroup[attrName], node, attrName);
const isAcceptedTagAttr = attrName in tagGroup && evaluateValue(tagGroup[attrName], node, attrName);

if (isAcceptedGlobalAttr || isAcceptedTagAttr)
switch (attrName)
{
switch (attrName)
case CONTENT_ATTR:
{
promises.push( transformMetaRefresh(node, attrName, eachURL) );
break;
}
case PING_ATTR:
{
case CONTENT_ATTR:
{
promises.push( transformMetaRefresh(node, attrName, eachURL) );
break;
}
case PING_ATTR:
{
promises.push( transformCommaSeparated(node, attrName, eachURL) );
break;
}
case SRCSET_ATTR:
{
promises.push( transformSrcset(node, attrName, eachURL) );
break;
}
default:
{
promises.push( transformDefault(node, attrName, eachURL) );
}
promises.push( transformCommaSeparated(node, attrName, eachURL) );
break;
}
case SRCSET_ATTR:
{
promises.push( transformSrcset(node, attrName, eachURL) );
break;
}
default:
{
promises.push( transformDefault(node, attrName, eachURL) );
}
}
});
}
}
});

return node;
});
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"private": true,
"name": "posthtml-urls",
"description": "PostHTML plugin for transforming URLs.",
"version": "2.0.0-alpha",
"name": "@11ty/posthtml-urls",
"description": "PostHTML plugin for transforming URLs. A fork of posthtml/posthtml-urls.",
"version": "1.0.0",
"license": "MIT",
"author": "Steven Vachon <[email protected]> (https://svachon.com)",
"repository": "github:posthtml/posthtml-urls",
"author": "Zach Leatherman <[email protected]> (https://zachleat.com/)",
"contributors": ["Steven Vachon <[email protected]> (https://svachon.com)"],
"repository": "github:11ty/posthtml-urls",
"main": "lib",
"dependencies": {
"evaluate-value": "^2.0.0",
"http-equiv-refresh": "^2.0.1",
"list-to-array": "^1.1.0",
"object.entries": "^1.1.0",
"object.entries": "^1.1.7",
"parse-srcset": "^1.0.2"
},
"devDependencies": {
"chai": "^4.2.0",
"coveralls": "^3.0.6",
"html-tags": "^3.1.0",
"html-tags": "^3.1.1",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"posthtml": "~0.11.6"
"posthtml": "~0.16.6"
},
"engines": {
"node": ">= 6"
Expand Down

0 comments on commit 76a600f

Please sign in to comment.