Skip to content

Commit

Permalink
Use better converter for embedded page filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Mar 25, 2024
1 parent 39c071b commit 3d23222
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions _tools/embedded-page-cacher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// fixes cross-origin issues with iframes. For instance, we want
// clicked links to open in the browser window and not within the iframe.


import fs from 'fs';
import followRedirects from 'follow-redirects';
const https = followRedirects.https;
import graymatter from 'gray-matter';
import filenamifyUrl from 'filenamify-url';

import process from 'process';
import minimist from 'minimist';
Expand Down Expand Up @@ -47,7 +47,7 @@ function cacheRemoteLinks(path) {
if (Object.keys(frontmatter.data).length > 0) {
let remoteUrl = frontmatter.data.embedded_remote;
if (remoteUrl) {
let slug = encodeURIComponent(remoteUrl);
let slug = filenamifyUrl(remoteUrl);
let outPath = outDir + '/' + slug + '/';
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath);
Expand Down Expand Up @@ -131,7 +131,7 @@ function cacheRemoteImages(html, toPath) {
const matches = html.matchAll(imgRegex);
for (const match of matches) {
let imgUrl = match[1];
let slug = encodeURIComponent(imgUrl);
let slug = filenamifyUrl(imgUrl);
html = html.replaceAll(imgUrl, "img/" + slug);
cacheRemoteImage(imgUrl, toPath + "img/" + slug);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"fix": "npm-run-all -p fix:*"
},
"devDependencies": {
"filenamify-url": "^3.1.0",
"follow-redirects": "^1.15.3",
"gray-matter": "^4.0.3",
"minimist": "^1.2.8",
Expand Down

0 comments on commit 3d23222

Please sign in to comment.