generated from just-the-docs/just-the-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AnimatedSwine37
committed
Apr 14, 2024
1 parent
341927a
commit 1d29ba2
Showing
8 changed files
with
7,100 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ _site/ | |
.bundle/ | ||
vendor/ | ||
|
||
.vs/ | ||
.vs/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function fromFile(content) { | ||
console.log("Running fromFile on") | ||
console.log(content) | ||
// Note that I removed the options object. If stuff breaks maybe add it back | ||
const result = matter.matter(content, {}); | ||
// in the absent of a body when serializing an entry we use an empty one | ||
// when calling `toFile`, so we don't want to add it when parsing. | ||
return { | ||
...result.data, | ||
...(result.content.trim() && { body: liquidLinksToNormal(result.content) }), | ||
}; | ||
} | ||
|
||
function toFile(data) { | ||
console.log("Running toFile on") | ||
console.log(data) | ||
|
||
const { body = '', ...meta } = data; | ||
|
||
// gray-matter always adds a line break at the end which trips our | ||
// change detection logic | ||
// https://github.com/jonschlinkert/gray-matter/issues/96 | ||
// Note that I removed the options object from the stringify call. If stuff breaks maybe add it back | ||
const trimLastLineBreak = body.slice(-1) !== '\n'; | ||
const file = matter.stringify(normalLinksToLiquid(body), meta, {}); | ||
return trimLastLineBreak && file.slice(-1) === '\n' ? file.slice(0, -1) : file; | ||
} | ||
|
||
// Converts liquid link tags to normal links so decap can handle them | ||
function liquidLinksToNormal(content) | ||
{ | ||
return content.replace(/{%link (.*?) %}/g, '/persona-modding-docs/$1'); | ||
} | ||
|
||
// Converts normal relative links to liquid link tabs | ||
function normalLinksToLiquid(content) | ||
{ | ||
return content.replace(/\]\((?:\/persona-modding-docs)?\/(assets\/images.*)\)/g, ']({%link $1 %})') | ||
} | ||
|
||
CMS.registerCustomFormat('jekyll', 'md', { | ||
fromFile: text => fromFile(text), | ||
toFile: value => toFile(value), | ||
}); |
Oops, something went wrong.