Skip to content

Commit

Permalink
Merge pull request #25 from mojodna/json-ld
Browse files Browse the repository at this point in the history
JSON-LD / Schema.org mapping
  • Loading branch information
mojodna authored Jan 25, 2019
2 parents d1a4910 + b39085d commit 7ca92f5
Show file tree
Hide file tree
Showing 8 changed files with 8,645 additions and 18,701 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
extends: [
"eslint:recommended",
"plugin:vue/recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"prettier/vue"
],
globals: {
Buffer: true,
Expand Down
42 changes: 35 additions & 7 deletions bin/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class STACRenderer extends Renderer {
route
);

await page.waitForSelector(options.renderAfterElementExists);

const result = {
originalRoute: route,
route: await page.evaluate("window.location.pathname"),
Expand All @@ -76,27 +78,40 @@ class STACRenderer extends Renderer {
}
}

const options = commandLineArgs([
{ name: "verbose", alias: "v", type: Boolean },
{ name: "help", alias: "h", type: Boolean },
{ name: "root", type: String, defaultOption: true }
]);
const options = commandLineArgs(
[
{ name: "verbose", alias: "v", type: Boolean },
{ name: "help", alias: "h", type: Boolean },
{ name: "public-url", alias: "p", type: String },
{ name: "root", type: String, defaultOption: true }
],
{
camelCase: true
}
);

if (options.help || options.root == null) {
console.warn("Usage: prerender [-v] [-h] <root catalog URL>");
console.warn("Usage: prerender [-v] [-h] [-p public URL] <root catalog URL>");
process.exit(1);
}

const slugify = _slugify.bind(null, options.root);

async function prerender(routes) {
let prerenderer;
let sitemap;

if (options.publicUrl) {
sitemap = fs.createWriteStream(
path.join(__dirname, "..", "dist", "sitemap.txt")
);
}

const uri = url.parse(options.root);

try {
const renderer = new STACRenderer({
renderAfterElementExists: ".container",
renderAfterElementExists: ".loaded",
// allow catalog requests
skipThirdPartyRequests: req => !req.url().includes(uri.hostname)
});
Expand All @@ -121,11 +136,24 @@ async function prerender(routes) {
} catch (err) {
console.warn(err.stack);
}

if (sitemap != null) {
sitemap.write(`${options.publicUrl}${route}\n`);
}
}
} finally {
if (prerenderer != null) {
prerenderer.destroy();
}

if (sitemap != null) {
sitemap.end();

await fs.writeFile(
path.join(__dirname, "..", "dist", "robots.txt"),
`sitemap: ${options.publicUrl}/sitemap.txt\n`
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Crawler extends Readable {
return;
}

const [url, type, ancestors] = this.pending.shift();
const [url, type, ancestors] = this.pending.pop();
this.seen.add([url, type, ancestors].join("::"));

try {
Expand Down
Loading

0 comments on commit 7ca92f5

Please sign in to comment.