|
| 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 | +} |
0 commit comments