Skip to content

Commit

Permalink
Fix absolute url for --meta-content-base in subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Apr 28, 2024
1 parent b849630 commit 6da2d43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions rev-web-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ const revWebAssets = {
assetDetail.references!++;
if (assetDetail && !assetDetail.usedIn!.includes(detail.canonical))
assetDetail.usedIn!.push(detail.canonical);
const trailingSlashes = /\/*$/;
const absoluteUrl = () => settings.metaContentBase!.replace(trailingSlashes, '/') +
assetDetail?.canonicalFolder + '/' + assetDetail?.hashedFilename;
const hashedUri = () => {
const hashed = revWebAssets.hashFilename(uri, assetDetail!.hash);
// Example: 'graphics/avatar.jpg' --> 'graphics/avatar.ad41b203.jpg'
const noBase = !settings.metaContentBase || !pre.startsWith('<meta');
const trailingSlashes = /\/*$/;
return noBase ? hashed : settings.metaContentBase!.replace(trailingSlashes, '/') + hashed;
return noBase ? revWebAssets.hashFilename(uri, assetDetail!.hash) : absoluteUrl();
};
return assetDetail?.hash ? pre + hashedUri() + post : matched;
};
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/subfolder/mock2.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset=utf-8>
<meta property=og:type content="website">
<meta property=og:image content="https://example.net/graphics/mock2.9e7dfdbd.jpg">
<meta property=og:image content="https://example.net/subfolder/graphics/mock2.9e7dfdbd.jpg">
<title>🔢🔢🔢 rev-web-assets 🔢🔢🔢</title>
<link rel=icon href=https://centerkey.com/graphics/bookmark.png>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/[email protected]/dist/css/pretty-print-json.css>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/subfolder/mock2.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset=utf-8>
<meta property=og:type content="website">
<meta property=og:image content="https://example.net/graphics/mock2.9e7dfdbd.jpg">
<meta property=og:image content="https://example.net/subfolder/graphics/mock2.9e7dfdbd.jpg">
<title>🔢🔢🔢 rev-web-assets 🔢🔢🔢</title>
<link rel=icon href=https://centerkey.com/graphics/bookmark.png>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/[email protected]/dist/css/pretty-print-json.css>
Expand Down

0 comments on commit 6da2d43

Please sign in to comment.