Skip to content

Commit

Permalink
🐛 Remove markdown from excerpt
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 9, 2022
1 parent 9dac3b1 commit 7531a0a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
};
};
Expand Down

0 comments on commit 7531a0a

Please sign in to comment.