diff --git a/by-feature.js b/by-feature.js index 1175b96..3d7ed33 100644 --- a/by-feature.js +++ b/by-feature.js @@ -4,5 +4,6 @@ module.exports = { getHtml: require('./recipes/by-feature/get-html'), lighthouseReport: require('./recipes/by-feature/lighthouse-report'), technologyStack: require('./recipes/by-feature/technology-stack'), - universalEmbed: require('./recipes/by-feature/universal-embed') + universalEmbed: require('./recipes/by-feature/universal-embed'), + jsonLd: require('./recipes/by-feature/json-ld') } diff --git a/recipes/by-feature/json-ld.js b/recipes/by-feature/json-ld.js new file mode 100644 index 0000000..8451b2c --- /dev/null +++ b/recipes/by-feature/json-ld.js @@ -0,0 +1,23 @@ +'use strict' + +const mql = require('@microlink/mql') + +module.exports = async (url, opts) => { + const { data } = await mql(url, { + meta: false, + data: { + jsonLd: { + selectorAll: 'script[type="application/ld+json"]' + } + }, + ...opts + }) + + return data.jsonLd +} + +module.exports.meta = { + name: 'Get JSON+LD', + description: 'Retrieve all JSON+LD elements present on the website', + examples: ['https://teslahunt.io/5YJSA7E49JF269238'] +} diff --git a/test/by-feature.js b/test/by-feature.js index 9aba3c6..c295e93 100644 --- a/test/by-feature.js +++ b/test/by-feature.js @@ -9,7 +9,8 @@ const { getHtml, lighthouseReport, technologyStack, - universalEmbed + universalEmbed, + jsonLd } = require('../by-feature') const apiKey = process.env.MICROLINK_API_KEY @@ -24,26 +25,37 @@ test('universal embed', async t => { }) test('technology stack', async t => { - const technologies = await technologyStack(technologyStack.meta.examples[0]) + const technologies = await technologyStack(technologyStack.meta.examples[0], { + apiKey + }) t.true(ow.isValid(technologies, ow.object.not.empty)) }) test('lighthouse report', async t => { - const report = await lighthouseReport(lighthouseReport.meta.examples[0]) + const report = await lighthouseReport(lighthouseReport.meta.examples[0], { + apiKey + }) t.true(ow.isValid(report, ow.object.not.empty)) }) test('get html', async t => { - const html = await getHtml(getHtml.meta.examples[0]) + const html = await getHtml(getHtml.meta.examples[0], { apiKey }) t.true(html.startsWith(' { - const screenshot = await fullyScreenshot(fullyScreenshot.meta.examples[0]) + const screenshot = await fullyScreenshot(fullyScreenshot.meta.examples[0], { + apiKey + }) t.true(ow.isValid(screenshot, ow.object.not.empty)) }) test('debug css', async t => { - const screenshot = await debugCss(debugCss.meta.examples[0]) + const screenshot = await debugCss(debugCss.meta.examples[0], { apiKey }) t.true(ow.isValid(screenshot, ow.object.not.empty)) }) + +test('retrieve JSON+lD', async t => { + const data = await jsonLd(jsonLd.meta.examples[0], { apiKey }) + t.true(ow.isValid(data, ow.array.not.empty)) +})