Skip to content

fix: correct og:image path in client build #212

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

Merged
merged 3 commits into from
Jun 26, 2020
Merged
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
30 changes: 29 additions & 1 deletion scripts/build-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const { copy, remove, readFile, writeFile, readdir } = require('fs-extra');
const {
copy,
remove,
readFile,
writeFile,
readdir,
rename,
} = require('fs-extra');
const { resolve, join } = require('path');
const { build } = require('./build');
const { openInBrowser } = require('@parcel/utils');
Expand Down Expand Up @@ -63,6 +70,26 @@ async function fixWebManifest({ dest }) {
]);
}

async function fixHtml({ dest }) {
const htmlContent = await readFile(join(dest, 'index.html'), 'utf8');

const [, ogImageName] = htmlContent.match(
/<meta property="og:image" content="\/?(site\.[0-9a-fA-F]{8}\.jpg)">/,
);

const replacer = new RegExp(`/${ogImageName}`, 'g');
const newContent = htmlContent.replace(
replacer,
'https://testing-playground.com/site.jpg',
'utf8',
);

await Promise.all([
rename(join(dest, ogImageName), join(dest, 'site.jpg')),
writeFile(join(dest, 'index.html'), newContent, 'utf8'),
]);
}

async function main() {
const dest = resolve('dist/client');
await remove(dest);
Expand All @@ -80,6 +107,7 @@ async function main() {
});

await fixWebManifest({ dest });
await fixHtml({ dest });

await workbox.generateSW(workboxConfig);

Expand Down