diff --git a/apps/public-docsite-v9/.storybook/fix-title.js b/apps/public-docsite-v9/.storybook/fix-title.js new file mode 100644 index 0000000000000..2bd55cf8cb82b --- /dev/null +++ b/apps/public-docsite-v9/.storybook/fix-title.js @@ -0,0 +1,31 @@ +const fs = require('fs'); +const path = require('path'); + +function fixTitle(filePath, title) { + const htmlDocumentPath = path.resolve(__dirname, filePath); + const htmlDocument = fs.readFileSync(htmlDocumentPath, 'utf-8'); + const updatedHtmlDocument = htmlDocument.replace(/.*<\/title>/, `<title>${title}`); + + fs.writeFileSync(htmlDocumentPath, updatedHtmlDocument); +} + +try { + const args = process.argv.slice(2); + const [title, distPath] = args; + + const storybookDistPath = `${distPath}/storybook`; + const indexPath = `${storybookDistPath}/index.html`; + const iframePath = `${storybookDistPath}/iframe.html`; + + console.log(`Rewriting index.html document title to ${title}.`); + fixTitle(indexPath, title); + + console.log(`Rewriting iframe.html document title to ${title}.`); + fixTitle(iframePath, title); + + console.log('Title rewrite complete.'); +} catch (error) { + console.log('Title rewrite failed.'); + console.error(error); + process.exit(1); +} diff --git a/apps/public-docsite-v9/package.json b/apps/public-docsite-v9/package.json index 9cd8c0ae6ec36..af4fbca88df0c 100644 --- a/apps/public-docsite-v9/package.json +++ b/apps/public-docsite-v9/package.json @@ -5,7 +5,7 @@ "description": "A collection of examples demonstrating how to upgrade from v8 to v9", "scripts": { "build": "just-scripts build", - "build-storybook": "build-storybook -o ./dist/storybook --docs", + "build-storybook": "build-storybook -o ./dist/storybook --docs && node ./.storybook/fix-title.js 'Fluent UI React v9' ../dist", "chromatic:branch": "npx chromatic@6.4.3 --project-token $CHROMATIC_PROJECT_TOKEN --exit-zero-on-changes --build-script-name build-storybook", "chromatic": "npx chromatic@6.4.3 --project-token $CHROMATIC_PROJECT_TOKEN --exit-zero-on-changes --build-script-name build-storybook --branch-name microsoft:master", "clean": "just-scripts clean",