Skip to content

Commit b7c610c

Browse files
committed
Merge branch 'main' into merge/from-main
2 parents 4a5498a + b1ca5b3 commit b7c610c

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
@@ -55,7 +55,7 @@
5555
"storybook:watch": "npm-run-all --parallel watch storybook:bundle:watch storybook",
5656
"storybook:bundle": "rollup -c ./.storybook/rollup.config.js",
5757
"storybook:bundle:watch": "rollup -c ./.storybook/rollup.config.js --watch",
58-
"storybook:build": "npm run storybook:bundle && npm run storybook:dev && build-storybook -s assets && cpx .storybook/CNAME storybook-static",
58+
"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' ../",
5959
"storybook:deploy": "npm run storybook:build && storybook-to-ghpages -e storybook-static",
6060
"setLicense": "gulp setLicense",
6161
"test": "jest",

0 commit comments

Comments
 (0)