From 7531a0ae876b42cb2e6b36ef5825f1eadb660437 Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Sun, 9 Oct 2022 15:07:47 +0200 Subject: [PATCH] :bug: Remove markdown from excerpt --- package-lock.json | 41 +++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/index.ts | 9 ++++++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 94460f7..91aef44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@koj/config": "^1.2.11", "emoji-flags": "^1.3.0", "fs-extra": "^10.1.0", + "markdown-to-txt": "^2.0.1", "prettier": "^2.7.1", "truncate-sentences": "^1.0.0" }, @@ -8648,6 +8649,11 @@ "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" }, + "node_modules/lodash.escape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.1.tgz", + "integrity": "sha512-nXEOnb/jK9g0DYMr1/Xvq6l5xMD7GDG55+GSYIYmS0G4tBk/hURD4JR9WCavs04t33WmJx9kCyp9vJ+mr4BOUw==" + }, "node_modules/lodash.escaperegexp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", @@ -8725,6 +8731,11 @@ "lodash.keys": "^3.0.0" } }, + "node_modules/lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha512-DhhGRshNS1aX6s5YdBE3njCCouPgnG29ebyHvImlZzXZf2SHgt+J08DHgytTPnpywNbO1Y8mNUFyQuIDBq2JZg==" + }, "node_modules/lodash.uniq": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", @@ -8796,6 +8807,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/markdown-to-txt": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/markdown-to-txt/-/markdown-to-txt-2.0.1.tgz", + "integrity": "sha512-Hsj7KTN8k1gutlLum3vosHwVZGnv8/cbYKWVkUyo/D1rzOYddbDesILebRfOsaVfjIBJank/AVOySBlHAYqfZw==", + "dependencies": { + "lodash.escape": "^4.0.1", + "lodash.unescape": "^4.0.1", + "marked": "^4.0.14" + } + }, "node_modules/marked": { "version": "4.0.17", "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.17.tgz", @@ -19473,6 +19494,11 @@ "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" }, + "lodash.escape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.1.tgz", + "integrity": "sha512-nXEOnb/jK9g0DYMr1/Xvq6l5xMD7GDG55+GSYIYmS0G4tBk/hURD4JR9WCavs04t33WmJx9kCyp9vJ+mr4BOUw==" + }, "lodash.escaperegexp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", @@ -19550,6 +19576,11 @@ "lodash.keys": "^3.0.0" } }, + "lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha512-DhhGRshNS1aX6s5YdBE3njCCouPgnG29ebyHvImlZzXZf2SHgt+J08DHgytTPnpywNbO1Y8mNUFyQuIDBq2JZg==" + }, "lodash.uniq": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", @@ -19605,6 +19636,16 @@ "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.3.0.tgz", "integrity": "sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==" }, + "markdown-to-txt": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/markdown-to-txt/-/markdown-to-txt-2.0.1.tgz", + "integrity": "sha512-Hsj7KTN8k1gutlLum3vosHwVZGnv8/cbYKWVkUyo/D1rzOYddbDesILebRfOsaVfjIBJank/AVOySBlHAYqfZw==", + "requires": { + "lodash.escape": "^4.0.1", + "lodash.unescape": "^4.0.1", + "marked": "^4.0.14" + } + }, "marked": { "version": "4.0.17", "resolved": "https://registry.npmjs.org/marked/-/marked-4.0.17.tgz", diff --git a/package.json b/package.json index d4022cf..aee0fcf 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@koj/config": "^1.2.11", "emoji-flags": "^1.3.0", "fs-extra": "^10.1.0", + "markdown-to-txt": "^2.0.1", "prettier": "^2.7.1", "truncate-sentences": "^1.0.0" }, diff --git a/src/index.ts b/src/index.ts index 2d899cd..4ddb6ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,10 @@ import { getInput, setFailed, setOutput } from "@actions/core"; import { execSync } from "child_process"; import { readdir, readFile, writeFile } from "fs-extra"; +import markdownToTxt from "markdown-to-txt"; import { join } from "path"; -import truncate from "truncate-sentences"; import { format } from "prettier"; +import truncate from "truncate-sentences"; interface Note { slug: string; @@ -31,7 +32,9 @@ const parseNoteFile = async (dirName: string, year: string, file: string): Promi "title: ", "" ) || - ((contents.split("\n").find((line) => line.startsWith("# ")) || "").split("# ")[1] || "").trim() || + ( + (contents.split("\n").find((line) => line.startsWith("# ")) || "").split("# ")[1] || "" + ).trim() || undefined; const excerpt = (contents.split("\n").find((line) => line.startsWith("excerpt: ")) || "").replace( @@ -59,7 +62,7 @@ const parseNoteFile = async (dirName: string, year: string, file: string): Promi slug: file, title: title, date, - excerpt: excerpt ? truncate(excerpt, 500) : undefined, + excerpt: excerpt ? truncate(markdownToTxt(excerpt), 500) : undefined, words: contents.split(" ").length, }; };