Skip to content

Commit

Permalink
Add WordPress import test
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 7, 2024
1 parent c919ff5 commit 02ba724
Show file tree
Hide file tree
Showing 8 changed files with 570 additions and 536 deletions.
533 changes: 1 addition & 532 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@11ty/import",
"version": "1.0.0",
"description": "Utility to import content from multiple services (and a CLI, too).",
"description": "Utility to import content from multiple services (and a CLI, too)",
"main": "src/Importer.js",
"type": "module",
"engines": {
Expand Down Expand Up @@ -38,8 +38,5 @@
"js-yaml": "^4.1.0",
"kleur": "^4.1.5",
"turndown": "^7.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
16 changes: 16 additions & 0 deletions src/DataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DataSource {
static UUID_PREFIX = "11tyaf";

#fetcher;
#fetchDataOverrides = {};
#outputFolder;

constructor() {
Expand All @@ -27,6 +28,11 @@ class DataSource {
return this.#fetcher;
}

// For testing
setDataOverride(url, data) {
this.#fetchDataOverrides[url] = data;
}

setLabel(label) {
this.label = label;
}
Expand Down Expand Up @@ -96,6 +102,15 @@ class DataSource {
}

async getData(url, type, showErrors = true) {
// For testing, all urls must be stubbed
if(Object.keys(this.#fetchDataOverrides).length > 0) {
if(this.#fetchDataOverrides[url]) {
return this.#fetchDataOverrides[url];
}

throw new Error("Testing error, missing data override url: " + url);
}

return this.fetcher.fetch(url, {
type,
fetchOptions: {
Expand Down Expand Up @@ -133,6 +148,7 @@ class DataSource {
entries.push(entry);
found++;
}

if(found === 0) {
break;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ class Importer {
return this.sources;
}

getSourcesForType(type) {
return this.sources.filter(entry => entry.constructor.TYPE === type);
}

addDataOverride(type, url, data) {
for(let source of this.getSourcesForType(type)) {
source.setDataOverride(url, data);
}
}

async getEntries(options = {}) {
let entries = [];
for(let source of this.sources) {
Expand Down
130 changes: 130 additions & 0 deletions test/sources/blog-awesome-author.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"id": 155431370,
"name": "Matt Johnson",
"url": "",
"description": "",
"link": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/",
"slug": "iamthedayofcurrenttaste",
"avatar_urls": {
"24": "https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=24&r=g",
"48": "https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=48&r=g",
"96": "https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=96&r=g"
},
"meta": [],
"yoast_head": "<!-- This site is optimized with the Yoast SEO plugin v23.8 - https://yoast.com/wordpress/plugins/seo/ -->\n<title>Matt Johnson, Author at Blog Awesome</title>\n<!-- Admin only notice: this page does not show a meta description because it does not have one, either write it for this page specifically or go into the [Yoast SEO - Settings] menu and set up a template. -->\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" />\n<link rel=\"canonical\" href=\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/\" />\n<meta property=\"og:locale\" content=\"en_US\" />\n<meta property=\"og:type\" content=\"profile\" />\n<meta property=\"og:title\" content=\"Matt Johnson, Author at Blog Awesome\" />\n<meta property=\"og:url\" content=\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/\" />\n<meta property=\"og:site_name\" content=\"Blog Awesome\" />\n<meta property=\"og:image\" content=\"https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=500&r=g\" />\n<meta name=\"twitter:card\" content=\"summary_large_image\" />\n<meta name=\"twitter:site\" content=\"@fontawesome\" />\n<script type=\"application/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"ProfilePage\",\"@id\":\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/\",\"url\":\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/\",\"name\":\"Matt Johnson, Author at Blog Awesome\",\"isPartOf\":{\"@id\":\"https://blog.fontawesome.com/#website\"},\"breadcrumb\":{\"@id\":\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https://blog.fontawesome.com/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Archives for Matt Johnson\"}]},{\"@type\":\"WebSite\",\"@id\":\"https://blog.fontawesome.com/#website\",\"url\":\"https://blog.fontawesome.com/\",\"name\":\"Blog Awesome\",\"description\":\"News and information from Font Awesome – the internet&#039;s favorite icon set; mixed with musings and nerdery from the team behind it.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https://blog.fontawesome.com/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https://blog.fontawesome.com/#/schema/person/7bc6a686f3fdf796f6e069c674ea7dbe\",\"name\":\"Matt Johnson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https://blog.fontawesome.com/#/schema/person/image/\",\"url\":\"https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=96&r=g\",\"contentUrl\":\"https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=96&r=g\",\"caption\":\"Matt Johnson\"},\"mainEntityOfPage\":{\"@id\":\"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/\"}}]}</script>\n<!-- / Yoast SEO plugin. -->",
"yoast_head_json": {
"title": "Matt Johnson, Author at Blog Awesome",
"robots": {
"index": "index",
"follow": "follow",
"max-snippet": "max-snippet:-1",
"max-image-preview": "max-image-preview:large",
"max-video-preview": "max-video-preview:-1"
},
"canonical": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/",
"og_locale": "en_US",
"og_type": "profile",
"og_title": "Matt Johnson, Author at Blog Awesome",
"og_url": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/",
"og_site_name": "Blog Awesome",
"og_image": [
{
"url": "https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=500&r=g"
}
],
"twitter_card": "summary_large_image",
"twitter_site": "@fontawesome",
"schema": {
"@context": "https://schema.org",
"@graph": [
{
"@type": "ProfilePage",
"@id": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/",
"url": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/",
"name": "Matt Johnson, Author at Blog Awesome",
"isPartOf": { "@id": "https://blog.fontawesome.com/#website" },
"breadcrumb": {
"@id": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/#breadcrumb"
},
"inLanguage": "en-US",
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"https://blog.fontawesome.com/author/iamthedayofcurrenttaste/"
]
}
]
},
{
"@type": "BreadcrumbList",
"@id": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/#breadcrumb",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://blog.fontawesome.com/"
},
{
"@type": "ListItem",
"position": 2,
"name": "Archives for Matt Johnson"
}
]
},
{
"@type": "WebSite",
"@id": "https://blog.fontawesome.com/#website",
"url": "https://blog.fontawesome.com/",
"name": "Blog Awesome",
"description": "News and information from Font Awesome – the internet&#039;s favorite icon set; mixed with musings and nerdery from the team behind it.",
"potentialAction": [
{
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://blog.fontawesome.com/?s={search_term_string}"
},
"query-input": {
"@type": "PropertyValueSpecification",
"valueRequired": true,
"valueName": "search_term_string"
}
}
],
"inLanguage": "en-US"
},
{
"@type": "Person",
"@id": "https://blog.fontawesome.com/#/schema/person/7bc6a686f3fdf796f6e069c674ea7dbe",
"name": "Matt Johnson",
"image": {
"@type": "ImageObject",
"inLanguage": "en-US",
"@id": "https://blog.fontawesome.com/#/schema/person/image/",
"url": "https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=96&r=g",
"contentUrl": "https://secure.gravatar.com/avatar/b548253c6adbbd36ce84487da009e1aa?s=96&r=g",
"caption": "Matt Johnson"
},
"mainEntityOfPage": {
"@id": "https://blog.fontawesome.com/author/iamthedayofcurrenttaste/"
}
}
]
}
},
"amp_review_panel_dismissed_for_template_mode": "",
"amp_dev_tools_enabled": false,
"_links": {
"self": [
{
"href": "https://blog.fontawesome.com/wp-json/wp/v2/users/155431370",
"targetHints": { "allow": ["GET", "POST", "PUT", "PATCH", "DELETE"] }
}
],
"collection": [
{ "href": "https://blog.fontawesome.com/wp-json/wp/v2/users" }
]
}
}
121 changes: 121 additions & 0 deletions test/sources/blog-awesome-categories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"id": 1,
"count": 91,
"description": "",
"link": "https://blog.fontawesome.com/category/uncategorized/",
"name": "Uncategorized",
"slug": "uncategorized",
"taxonomy": "category",
"parent": 0,
"meta": [],
"yoast_head": "\u003C!-- This site is optimized with the Yoast SEO plugin v23.8 - https://yoast.com/wordpress/plugins/seo/ --\u003E\n\u003Ctitle\u003EUncategorized Archives - Blog Awesome\u003C/title\u003E\n\u003Cmeta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" /\u003E\n\u003Clink rel=\"canonical\" href=\"https://blog.fontawesome.com/category/uncategorized/\" /\u003E\n\u003Cmeta property=\"og:locale\" content=\"en_US\" /\u003E\n\u003Cmeta property=\"og:type\" content=\"article\" /\u003E\n\u003Cmeta property=\"og:title\" content=\"Uncategorized Archives - Blog Awesome\" /\u003E\n\u003Cmeta property=\"og:url\" content=\"https://blog.fontawesome.com/category/uncategorized/\" /\u003E\n\u003Cmeta property=\"og:site_name\" content=\"Blog Awesome\" /\u003E\n\u003Cmeta name=\"twitter:card\" content=\"summary_large_image\" /\u003E\n\u003Cmeta name=\"twitter:site\" content=\"@fontawesome\" /\u003E\n\u003Cscript type=\"application/ld+json\" class=\"yoast-schema-graph\"\u003E{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"CollectionPage\",\"@id\":\"https://blog.fontawesome.com/category/uncategorized/\",\"url\":\"https://blog.fontawesome.com/category/uncategorized/\",\"name\":\"Uncategorized Archives - Blog Awesome\",\"isPartOf\":{\"@id\":\"https://blog.fontawesome.com/#website\"},\"breadcrumb\":{\"@id\":\"https://blog.fontawesome.com/category/uncategorized/#breadcrumb\"},\"inLanguage\":\"en-US\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://blog.fontawesome.com/category/uncategorized/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https://blog.fontawesome.com/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Uncategorized\"}]},{\"@type\":\"WebSite\",\"@id\":\"https://blog.fontawesome.com/#website\",\"url\":\"https://blog.fontawesome.com/\",\"name\":\"Blog Awesome\",\"description\":\"News and information from Font Awesome – the internet&#039;s favorite icon set; mixed with musings and nerdery from the team behind it.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https://blog.fontawesome.com/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}\u003C/script\u003E\n\u003C!-- / Yoast SEO plugin. --\u003E",
"yoast_head_json": {
"title": "Uncategorized Archives - Blog Awesome",
"robots": {
"index": "index",
"follow": "follow",
"max-snippet": "max-snippet:-1",
"max-image-preview": "max-image-preview:large",
"max-video-preview": "max-video-preview:-1"
},
"canonical": "https://blog.fontawesome.com/category/uncategorized/",
"og_locale": "en_US",
"og_type": "article",
"og_title": "Uncategorized Archives - Blog Awesome",
"og_url": "https://blog.fontawesome.com/category/uncategorized/",
"og_site_name": "Blog Awesome",
"twitter_card": "summary_large_image",
"twitter_site": "@fontawesome",
"schema": {
"@context": "https://schema.org",
"@graph": [
{
"@type": "CollectionPage",
"@id": "https://blog.fontawesome.com/category/uncategorized/",
"url": "https://blog.fontawesome.com/category/uncategorized/",
"name": "Uncategorized Archives - Blog Awesome",
"isPartOf": {
"@id": "https://blog.fontawesome.com/#website"
},
"breadcrumb": {
"@id": "https://blog.fontawesome.com/category/uncategorized/#breadcrumb"
},
"inLanguage": "en-US"
},
{
"@type": "BreadcrumbList",
"@id": "https://blog.fontawesome.com/category/uncategorized/#breadcrumb",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://blog.fontawesome.com/"
},
{
"@type": "ListItem",
"position": 2,
"name": "Uncategorized"
}
]
},
{
"@type": "WebSite",
"@id": "https://blog.fontawesome.com/#website",
"url": "https://blog.fontawesome.com/",
"name": "Blog Awesome",
"description": "News and information from Font Awesome – the internet&#039;s favorite icon set; mixed with musings and nerdery from the team behind it.",
"potentialAction": [
{
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://blog.fontawesome.com/?s={search_term_string}"
},
"query-input": {
"@type": "PropertyValueSpecification",
"valueRequired": true,
"valueName": "search_term_string"
}
}
],
"inLanguage": "en-US"
}
]
}
},
"_links": {
"self": [
{
"href": "https://blog.fontawesome.com/wp-json/wp/v2/categories/1",
"targetHints": {
"allow": [
"GET"
]
}
}
],
"collection": [
{
"href": "https://blog.fontawesome.com/wp-json/wp/v2/categories"
}
],
"about": [
{
"href": "https://blog.fontawesome.com/wp-json/wp/v2/taxonomies/category"
}
],
"wp:post_type": [
{
"href": "https://blog.fontawesome.com/wp-json/wp/v2/posts?categories=1"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
Loading

0 comments on commit 02ba724

Please sign in to comment.