WooCommerce Docs: Handle multiple category posts (#39352)
This commit is contained in:
parent
ddf9a7741a
commit
b1cb905464
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
post_title: Integration Testing
|
||||||
|
---
|
||||||
|
|
||||||
|
## Integration Tests
|
||||||
|
|
||||||
|
Elementary, my dear Watson! Write integration tests.
|
|
@ -7,7 +7,7 @@
|
||||||
"post_title": "Local Development",
|
"post_title": "Local Development",
|
||||||
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/get-started/local-development.md",
|
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/get-started/local-development.md",
|
||||||
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/get-started/local-development.md",
|
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/get-started/local-development.md",
|
||||||
"id": "c068ce54044fa44c760a69bd71ef21274f2a5a37"
|
"id": "c387a046f8307a4f459091a2c45e82263b45e777"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"categories": [
|
"categories": [
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
"post_title": "Install the Plugin",
|
"post_title": "Install the Plugin",
|
||||||
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/get-started/installation/install-plugin.md",
|
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/get-started/installation/install-plugin.md",
|
||||||
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/get-started/installation/install-plugin.md",
|
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/get-started/installation/install-plugin.md",
|
||||||
"id": "fb59bd01dda7b090e5b0a557948e155a6b679d6a"
|
"id": "c4ac8c48c3445186189d15f01028eacd517b9707"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"categories": []
|
"categories": []
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
"post_title": "What Went Wrong?",
|
"post_title": "What Went Wrong?",
|
||||||
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/get-started/troubleshooting/what-went-wrong.md",
|
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/get-started/troubleshooting/what-went-wrong.md",
|
||||||
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/get-started/troubleshooting/what-went-wrong.md",
|
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/get-started/troubleshooting/what-went-wrong.md",
|
||||||
"id": "1f88c4d039e72c059c928ab475ad1ea0a02c8abb"
|
"id": "f87dcc9b8177ad2d8549ef7298d66fb7c8616d71"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"categories": []
|
"categories": []
|
||||||
|
@ -44,11 +44,17 @@
|
||||||
"post_title": "Unit Testing",
|
"post_title": "Unit Testing",
|
||||||
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/testing/unit-tests.md",
|
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/testing/unit-tests.md",
|
||||||
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/testing/unit-tests.md",
|
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/testing/unit-tests.md",
|
||||||
"id": "120770c899215a889246b47ac883e4dda1f97b8b"
|
"id": "1b9de005cc5da3b49d12c24837a5a574aa58ad96"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"post_title": "Integration Testing",
|
||||||
|
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/plugins/woocommerce-docs/example-docs/testing/integration-tests.md",
|
||||||
|
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce-docs/example-docs/testing/integration-tests.md",
|
||||||
|
"id": "ee3fd61c9d7b13614e4431708c336f20c9779e1f"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"categories": []
|
"categories": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hash": "7f0f6f0c39187a5ee2f939d7a0af56538aaeb7f040f56e6dd62458e34a0491bd"
|
"hash": "84a06ceffaced22a955a131c1272ec9a1d14ae0a7cf9bac4ed21874384f86e9a"
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
post_title: Integration Testing
|
||||||
|
---
|
||||||
|
|
||||||
|
## Integration Tests
|
||||||
|
|
||||||
|
Elementary, my dear Watson! Write integration tests.
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
category_title: Unit Testing
|
post_title: Unit Testing
|
||||||
---
|
---
|
||||||
|
|
||||||
## Unit Test
|
## Unit Test
|
||||||
|
|
|
@ -38,6 +38,29 @@ describe( 'generateManifest', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
it( 'should generate a manifest with categories that contain all markdown files in a location as individual posts', async () => {
|
||||||
|
// generate the manifest from fixture directory
|
||||||
|
const manifest = await generateManifestFromDirectory(
|
||||||
|
rootDir,
|
||||||
|
dir,
|
||||||
|
'example-docs',
|
||||||
|
'https://example.com',
|
||||||
|
'https://example.com/edit'
|
||||||
|
);
|
||||||
|
|
||||||
|
const topLevelCategories = manifest.categories;
|
||||||
|
|
||||||
|
expect( topLevelCategories[ 1 ].category_title ).toEqual(
|
||||||
|
'Testing WooCommerce'
|
||||||
|
);
|
||||||
|
|
||||||
|
const posts = topLevelCategories[ 1 ].posts;
|
||||||
|
|
||||||
|
expect( posts ).toHaveLength( 2 );
|
||||||
|
expect( posts[ 0 ].post_title ).toEqual( 'Unit Testing' );
|
||||||
|
expect( posts[ 1 ].post_title ).toEqual( 'Integration Testing' );
|
||||||
|
} );
|
||||||
|
|
||||||
it( 'should create categories with titles where there is no index README', async () => {
|
it( 'should create categories with titles where there is no index README', async () => {
|
||||||
const manifest = await generateManifestFromDirectory(
|
const manifest = await generateManifestFromDirectory(
|
||||||
rootDir,
|
rootDir,
|
||||||
|
|
|
@ -54,12 +54,16 @@ async function processDirectory(
|
||||||
|
|
||||||
const markdownFiles = glob.sync( path.join( subDirectory, '*.md' ) );
|
const markdownFiles = glob.sync( path.join( subDirectory, '*.md' ) );
|
||||||
|
|
||||||
|
// If there are markdown files in this directory, add a posts array to the category. Otherwise, assume its a top level category that will contain subcategories.
|
||||||
|
if ( markdownFiles.length > 0 ) {
|
||||||
|
category.posts = [];
|
||||||
|
}
|
||||||
|
|
||||||
markdownFiles.forEach( ( filePath ) => {
|
markdownFiles.forEach( ( filePath ) => {
|
||||||
if ( filePath !== readmePath || ! checkReadme ) {
|
if ( filePath !== readmePath || ! checkReadme ) {
|
||||||
// Skip README.md which we have already processed.
|
// Skip README.md which we have already processed.
|
||||||
const fileContent = fs.readFileSync( filePath, 'utf-8' );
|
const fileContent = fs.readFileSync( filePath, 'utf-8' );
|
||||||
const fileFrontmatter = generatePostFrontMatter( fileContent );
|
const fileFrontmatter = generatePostFrontMatter( fileContent );
|
||||||
category.posts = [];
|
|
||||||
|
|
||||||
if ( baseUrl.includes( 'github' ) ) {
|
if ( baseUrl.includes( 'github' ) ) {
|
||||||
fileFrontmatter.edit_url = generateFileUrl(
|
fileFrontmatter.edit_url = generateFileUrl(
|
||||||
|
|
Loading…
Reference in New Issue