Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to import CORS guide #531

Merged
4 commits merged into from May 31, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ content/learn/design-principles.md
content/docs/reference/spec.md
content/docs/reference/spec/*.md
content/docs/reference/components/**/*.md
content/docs/guides/amp-core-requests.md
1 change: 1 addition & 0 deletions gulpfile.js
Expand Up @@ -32,6 +32,7 @@ gulp.task('import-docs', function (cb) {
if (err instanceof Error) {
cb(err);
}
//console.log(stdout);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purposely kept it commented out because I'm always forgetting how to turn it on. I thought it no harm to leave it in, but commented.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, all good then!

cb();
});
});
Expand Down
11 changes: 7 additions & 4 deletions scripts/import_docs.js
Expand Up @@ -67,10 +67,11 @@ function getDependencies(content) {
// remove inline code
.replace(/`[^`]+`/g, '')
// find all used amp tags in the page
.match(/<amp-([^>\s]+)[^>]*>/g);
.match(/<amp-((?!img[\/\s>])[^>\s]+)[^>]*>/g);

console.log("Dependencies: " + dependencies);
if (dependencies) {
return Array.from(new Set(dependencies.map(item => item.match(/<amp-([^>\s]+)[^>]*>/)[1])));
return Array.from(new Set(dependencies.map(item => item.match(/<amp-((?!img[\/\s>])[^>\s]+)[^>]*>/)[1])));
}

return null;
Expand All @@ -80,12 +81,13 @@ function getDependencies(content) {
function savePage(config, callback) {

var optionalTOC = config.content.indexOf('[TOC]') > -1 ? 'toc: true\n' : '';
var optionalCategory = (config.category ? "\n$category: " + config.category : '');
var optionalDependencies = getDependencies(config.content);
optionalDependencies = optionalDependencies ? '\ncomponents:\n' + ' - ' + optionalDependencies.join('\n - ') + '\n' : '';

var frontMatter = `---
$title: "${config.title}"
$order: ${config.order || 0}
$order: ${config.order || 0}${optionalCategory}
${optionalTOC}${optionalDependencies}---
`;

Expand Down Expand Up @@ -139,7 +141,8 @@ importData.forEach((item) => {
destination: '../content/' + item.to,
content: (item.toc ? '[TOC]\n' : '') + pageContent,
title: item.title,
order: item.order
order: item.order,
category: (item.category ? item.category : '')
}, function (err) {
if (err) throw err;
console.log('Successfully imported: ' + item.title);
Expand Down
9 changes: 8 additions & 1 deletion scripts/import_docs.json
Expand Up @@ -23,5 +23,12 @@
"order": 3,
"from": "spec/amp-boilerplate.md",
"to": "docs/reference/spec/amp-boilerplate.md"
},
{
"title": "CORS in AMP",
"order": 10,
"from": "spec/amp-cors-requests.md",
"to": "docs/guides/amp-cors-requests.md",
"category": "Deploy"
}
]
]