Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into component/icon
Browse files Browse the repository at this point in the history
  • Loading branch information
HQCuong committed Dec 21, 2023
2 parents 571a664 + aba7969 commit 2427e07
Show file tree
Hide file tree
Showing 59 changed files with 2,102 additions and 402 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Demo.vue
# Vitepress
docs/.vitepress/dist
docs/.vitepress/cache
docs/components-content
docs/components-meta
docs/assets/components-meta
docs/assets/components-content
docs/assets/components-types
.cache
69 changes: 1 addition & 68 deletions build/gen-docs-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ type ComponentContent = {
keywords: string[];
}

const contentPath = './docs/components-content';
const componentsPath = './src/components';
const contentPath = './docs/assets/components-content';

function getContent(filePaths: string[]): void {
for (const f of filePaths) {
Expand Down Expand Up @@ -49,66 +48,6 @@ function getContent(filePaths: string[]): void {
path.join(contentPath, `${componentName}.json`),
JSON.stringify(ast, undefined, 2),
);

// Append to index.js
fs.appendFileSync(
path.join(contentPath, 'index.js'),
`export { default as ${componentName} } from './${componentName}.json';\n`,
);

// Update component docs
updateComponentDocs(componentName, ast);

console.log(`Component content generated for ${componentName}`);
}
}

/**
* Update source component docs with content from Polaris docs
*
* @param componentName
* @param ast
*/
function updateComponentDocs(componentName: string, ast: ComponentContent): void {
// Find docs from src/components to add content to
const componentDir = path.join(componentsPath, componentName);
const componentDocPath = path.join(componentDir, 'README.md');

if (fs.existsSync(componentDir) && fs.existsSync(componentDocPath)) {
const componentDoc = fs.readFileSync(componentDocPath, 'utf8');

// Get the frontmatter
const componentDocMatch = componentDoc.match(/---\n(.*?)\n---/s);
const componentDocFrontmatter = componentDocMatch ? componentDocMatch[1] : '';

// Remove description, bestpractices, and keywords from frontmatter
let componentDocNewFrontmatter = componentDocFrontmatter.replace(/\ndescription:.*?($|\n\w)/s, '$1');
// componentDocNewFrontmatter = componentDocNewFrontmatter.replace(/bestpractices:.*?($|\n\w)/s, '$1');
componentDocNewFrontmatter = componentDocNewFrontmatter.replace(/head:(.*?)($|\n\w)/s, '$2');
componentDocNewFrontmatter = componentDocNewFrontmatter.trim();

// Serialize keywords to
// keywords:
// - foo
// - bar
const keywords = ast.keywords.map((keyword) => `${keyword.trim().replace(/\s/g, '-')}`).join(' ');

// // Append content to head frontmatter
componentDocNewFrontmatter = componentDocNewFrontmatter + `
description: ${ast.description}
head:
- - meta
- name: keywords
content: ${keywords}`;

// Replace frontmatter
const componentDocNew = componentDoc.replace(componentDocFrontmatter, componentDocNewFrontmatter);

// Write to file
fs.writeFileSync(
componentDocPath,
componentDocNew,
);
}
}

Expand All @@ -122,12 +61,6 @@ export function generateDocsContent() {
fs.mkdirSync(contentDir, { recursive: true });
}

fs.writeFileSync(
path.join(contentPath, 'index.js'),
'',
);


getContent(paths);

console.log('All component content generated!');
Expand Down
Loading

0 comments on commit 2427e07

Please sign in to comment.