Skip to content

Commit

Permalink
Allow any article in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Dec 26, 2024
1 parent b2e835a commit fbe06d3
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions scripts/preview.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
const http = require('http');
const fs = require('fs');
const Parser = require('../dist/mercury.js');

function followPath(path) {
const rootPath = `fixtures/${path}`;
const isDirectory = fs.lstatSync(rootPath).isDirectory();

if (isDirectory) {
return `${rootPath}/${fs.readdirSync(rootPath)[0]}`;
}

return rootPath;
}

/**
* @param {string} reqPath
* @returns string | null
*/
async function parseFixture(reqPath) {
const reqURL = new URL(`https://example.com${reqPath}`);
const fixturePath = reqURL.pathname;
const url = reqURL.searchParams.get('article_url');

const html = fs.readFileSync(followPath(fixturePath)).toString();

const json = await Parser.parse(url, { html, fallback: false });
const json = await Parser.parse(url, { fallback: false });

return `<h1>${json.title}</h1><img src=${
json.lead_image_url
Expand Down

0 comments on commit fbe06d3

Please sign in to comment.