Skip to content

Commit

Permalink
Merge pull request #531 from ampproject/docs-import-CORS-guide
Browse files Browse the repository at this point in the history
Add functionality to import CORS guide
  • Loading branch information
Barb Paduch committed May 31, 2017
2 parents 7dc188c + a1e8ab0 commit f08239d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
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);
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"
}
]
]

0 comments on commit f08239d

Please sign in to comment.