Skip to content

Commit

Permalink
Update markdown-utils.js (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs authored Aug 25, 2022
1 parent 2b3cdb0 commit 7674ce8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/markdown-utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
const _ = require("lodash")
const yaml = require("yaml")

const getTrailingSlashWithPermalink = (permalink) =>
permalink.endsWith("/") ? permalink : `${permalink}/`

const retrieveDataFromMarkdown = (fileContent) => {
// eslint-disable-next-line no-unused-vars
const [unused, encodedFrontMatter, ...pageContent] = fileContent.split("---")
const frontMatter = yaml.parse(encodedFrontMatter)
return { frontMatter, pageContent: pageContent.join("---") }
}

const convertDataToMarkdown = (frontMatter, pageContent) => {
const convertDataToMarkdown = (originalFrontMatter, pageContent) => {
const frontMatter = _.clone(originalFrontMatter)
const { permalink } = frontMatter
if (permalink) {
frontMatter.permalink = getTrailingSlashWithPermalink(permalink)
}
const newFrontMatter = yaml.stringify(frontMatter)
const newContent = ["---\n", newFrontMatter, "---\n", pageContent].join("")
return newContent
Expand Down

0 comments on commit 7674ce8

Please sign in to comment.