Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore cdn #6

Merged
merged 4 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci

publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion lib/html-inline-external.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"files": [
"lib/**"
],
"version": "1.0.9",
"version": "1.0.10",
"description": "Helps include/inline external Script/CSS/Images and compiles into a Single HTML page.",
"main": "lib/html-inline-external.js",
"repository": "https://github.com/okrohan/html-inline-external.git",
"author": "okrohan",
"license": "MIT",
"private": false,
"scripts": {
"lint": "eslint **/*.js --fix",
"lint": "eslint src/*.js --fix",
"minify": "minify ./src/html-inline-external.js ./src/cli.js --out-dir ./lib --mangle"
},
"dependencies": {
Expand Down
12 changes: 11 additions & 1 deletion src/html-inline-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const base64Map = {
gif: 'image/jpeg',
};

const ignoreSourceStartingWith = [
'http://',
'https://',
];

const containsIgnoreSourceStartingWith = (src) => ignoreSourceStartingWith
.some((ignoreString) => src.startsWith(ignoreString));

const resolveImageToBase64 = ({ element, srcAttributeName = 'src' }) => {
const src = element.getAttribute(srcAttributeName);
if (!src || src.startsWith('http')) return Promise.resolve();
Expand All @@ -37,7 +45,7 @@ const resolveImageToBase64 = ({ element, srcAttributeName = 'src' }) => {

const resolveExternalScript = ({ element }) => {
if (!element.getAttribute('src')) return Promise.resolve();

if (containsIgnoreSourceStartingWith(element.getAttribute('src'))) return Promise.resolve();
return getFileString(resolveDirPath(element.getAttribute('src'))).then((file) => {
element.innerHTML = file;
element.removeAttribute('src');
Expand All @@ -46,6 +54,7 @@ const resolveExternalScript = ({ element }) => {

const resolveExternalIcon = async ({ element }) => {
if (!element.getAttribute('href')) return Promise.resolve();
if (containsIgnoreSourceStartingWith(element.getAttribute('href'))) return Promise.resolve();
return resolveImageToBase64({ element, srcAttributeName: 'href' });
};

Expand All @@ -54,6 +63,7 @@ const resolveExternalStyleSheet = ({ element }) => {
const { parentElement } = element;

if (!href) return Promise.resolve();
if (containsIgnoreSourceStartingWith(element.getAttribute('href'))) return Promise.resolve();

return getFileString(resolveDirPath(href)).then((file) => {
const style = document.createElement('style');
Expand Down
Loading