Skip to content

Commit b1ca5b3

Browse files
authored
bug: fix html title for mgt.dev (#2019)
1 parent 31c8e8a commit b1ca5b3

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

.storybook/fix-title.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
function fixTitle(filePath, title) {
5+
const htmlDocumentPath = path.resolve(__dirname, filePath);
6+
const htmlDocument = fs.readFileSync(htmlDocumentPath, 'utf-8');
7+
const updatedHtmlDocument = htmlDocument.replace(/<title>.*<\/title>/, `<title>${title}</title>`);
8+
9+
fs.writeFileSync(htmlDocumentPath, updatedHtmlDocument);
10+
}
11+
12+
function addSeoTags(filePath, title) {
13+
const htmlDocumentPath = path.resolve(__dirname, filePath);
14+
const htmlDocument = fs.readFileSync(htmlDocumentPath, 'utf-8');
15+
const updatedHtmlDocument = htmlDocument.replace(
16+
/<\/title>/,
17+
`</title>
18+
<meta name="og:title" content="${title}"></meta>
19+
<meta name="og:type" content="website"></meta>
20+
<meta name="og:description" content="Use Microsoft Graph Toolkit to find authentication providers and reusable, framework-agnostic web components for accessing and working with Microsoft Graph."></meta>
21+
<meta name="description" content="Use Microsoft Graph Toolkit to find authentication providers and reusable, framework-agnostic web components for accessing and working with Microsoft Graph."></meta>
22+
`
23+
);
24+
25+
fs.writeFileSync(htmlDocumentPath, updatedHtmlDocument);
26+
}
27+
28+
try {
29+
const args = process.argv.slice(2);
30+
const [title, distPath] = args;
31+
32+
const storybookDistPath = `${distPath}storybook-static`;
33+
const indexPath = `${storybookDistPath}/index.html`;
34+
const iframePath = `${storybookDistPath}/iframe.html`;
35+
36+
console.log(`Rewriting ${indexPath} document title to ${title}.`);
37+
fixTitle(indexPath, title);
38+
console.log(`Adding SeoTags to ${indexPath}.`);
39+
addSeoTags(indexPath, title);
40+
41+
console.log(`Rewriting iframe.html document title to ${title}.`);
42+
fixTitle(iframePath, title);
43+
44+
console.log('Title rewrite complete.');
45+
} catch (error) {
46+
console.log('Title rewrite failed.');
47+
console.error(error);
48+
process.exit(1);
49+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"storybook:watch": "npm-run-all --parallel watch storybook:bundle:watch storybook",
4444
"storybook:bundle": "rollup -c ./.storybook/rollup.config.js",
4545
"storybook:bundle:watch": "rollup -c ./.storybook/rollup.config.js --watch",
46-
"storybook:build": "npm run storybook:bundle && npm run storybook:dev && build-storybook -s assets && cpx .storybook/CNAME storybook-static",
46+
"storybook:build": "npm run storybook:bundle && npm run storybook:dev && build-storybook -s assets && cpx .storybook/CNAME storybook-static && node ./.storybook/fix-title.js 'Microsoft Graph Toolkit Playground' ../",
4747
"storybook:deploy": "npm run storybook:build && storybook-to-ghpages -e storybook-static",
4848
"setLicense": "gulp setLicense",
4949
"version:tsc": "tsc -v"

0 commit comments

Comments
 (0)