diff --git a/README.md b/README.md index 28b7b3a..d416f94 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A small utility (and CLI) to import content files from various content sources. - Downloads all referenced assets (images, videos, stylesheets, scripts, etc) in content and co-locates the assets with the content. - Works with a bunch of different data sources (see below). - **Resumable**: Can stop and resume a large import later, reusing a local cache (with configurable cache duration) -- **Safe**: avoids overwriting existing files by default (unless you opt-in with `--overwrite`). +- **Repeatable**: avoids overwriting existing content files (unless you opt-in with `--overwrite`). - This allows you to continue using an import source for new content while editing the already imported content. - Use `--dryrun` for testing without writing any files. diff --git a/package-lock.json b/package-lock.json index b073994..8170fad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@11ty/eleventy-fetch": "^5.0.0-beta.7", "@11ty/posthtml-urls": "^1.0.0", + "@sindresorhus/slugify": "^2.2.1", "dotenv": "^16.4.5", "fast-xml-parser": "^4.5.0", "filesize": "^10.1.6", @@ -22,7 +23,7 @@ "turndown": "^7.2.0" }, "bin": { - "import": "cli.js" + "eleventy-import": "cli.js" }, "engines": { "node": ">=18" @@ -101,6 +102,37 @@ "node": ">=14.0.0" } }, + "node_modules/@sindresorhus/slugify": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/slugify/-/slugify-2.2.1.tgz", + "integrity": "sha512-MkngSCRZ8JdSOCHRaYd+D01XhvU3Hjy6MGl06zhOk614hp9EOAp5gIkBeQg7wtmxpitU6eAL4kdiRMcJa2dlrw==", + "license": "MIT", + "dependencies": { + "@sindresorhus/transliterate": "^1.0.0", + "escape-string-regexp": "^5.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@sindresorhus/transliterate": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/transliterate/-/transliterate-1.6.0.tgz", + "integrity": "sha512-doH1gimEu3A46VX6aVxpHTeHrytJAG6HgdxntYnCFiIFHEM/ZGpG8KiZGBChchjQmG0XFIBL552kBTjVcMZXwQ==", + "license": "MIT", + "dependencies": { + "escape-string-regexp": "^5.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -352,6 +384,18 @@ "node": ">= 0.4" } }, + "node_modules/escape-string-regexp": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/evaluate-value": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/evaluate-value/-/evaluate-value-2.0.0.tgz", diff --git a/package.json b/package.json index f51a6d1..84d92e8 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "dependencies": { "@11ty/eleventy-fetch": "^5.0.0-beta.7", "@11ty/posthtml-urls": "^1.0.0", + "@sindresorhus/slugify": "^2.2.1", "dotenv": "^16.4.5", "fast-xml-parser": "^4.5.0", "filesize": "^10.1.6", diff --git a/src/DataSource/WordPressApi.js b/src/DataSource/WordPressApi.js index 9a6f048..f90bc27 100644 --- a/src/DataSource/WordPressApi.js +++ b/src/DataSource/WordPressApi.js @@ -173,6 +173,11 @@ class WordPressApi extends DataSource { metadata, }; + if(metadata.categories) { + // map WordPress categories for use in Eleventy tags (not WordPress metadata tags, which are different) + obj.tags = metadata.categories; + } + if(entry.og_image) { obj.metadata.opengraphImage = { width: entry.og_image?.width, diff --git a/src/Importer.js b/src/Importer.js index c292944..6759241 100644 --- a/src/Importer.js +++ b/src/Importer.js @@ -1,8 +1,9 @@ import path from "node:path"; +import { createRequire } from "node:module"; import fs from "graceful-fs"; import yaml from "js-yaml"; import kleur from "kleur"; -import { createRequire } from "node:module"; +import slugify from '@sindresorhus/slugify'; import { Logger } from "./Logger.js"; import { Fetcher } from "./Fetcher.js"; @@ -309,6 +310,15 @@ class Importer { // TODO map metadata.categories and/or metadata.tags to Eleventy `tags` } + if(entry.tags) { + if(!Array.isArray(entry.tags)) { + entry.tags = [entry.tags]; + } + + // slugify the tags + data.tags = entry.tags.map(tag => slugify(tag)); + } + // https://www.npmjs.com/package/js-yaml#dump-object---options- let frontMatter = yaml.dump(data, { // sortKeys: true,