-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for fenced files markdown component
- Loading branch information
Showing
10 changed files
with
211 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,4 @@ | ||
- [Vue Components in Markdown](/posts/markdown-components-in-vue) | ||
- [React Components in Markdown](https://press-react.servicestack.net/posts/markdown-components-in-react) | ||
- [.NET Razor SSG Vue Components in Markdown](https://razor-ssg.web-templates.io/posts/javascript) | ||
- [.NET Blazor Vue Components in Markdown](https://blazor-vue.web-templates.io/posts/javascript) |
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
Empty file.
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,67 @@ | ||
<template> | ||
<FileLayout :files="files" /> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import FileLayout from '@/components/FileLayout.vue' | ||
const props = defineProps<{ | ||
body: string | ||
}>() | ||
/* Takes an ascii string of indented folder and file paths: | ||
const from = `/meta | ||
/2022 | ||
all.json | ||
posts.json | ||
videos.json | ||
/2023 | ||
all.json | ||
posts.json | ||
all.json | ||
index.json` | ||
// and returns a nested object representing the file structure: | ||
const to = { | ||
meta: { | ||
2022: { _: ['all.json','posts.json','videos.json'] }, | ||
2023: { _: ['all.json','posts.json'] }, | ||
_: ['all.json','index.json'] | ||
} | ||
} | ||
*/ | ||
function parseFileStructure(ascii: string) { | ||
const parseLineIndentation = (line:string) => { | ||
const match = line.match(/^(\s*)/) | ||
return match ? match[0].length / 2 : 0 | ||
} | ||
const lines = ascii.trim().split("\n") | ||
const root = {} | ||
let currentPath: any = [root] | ||
lines.forEach((line) => { | ||
const name = line.trim() | ||
const isFile = name.includes(".") | ||
const level = parseLineIndentation(line) | ||
// Navigate up the currentPath to find the current level's parent | ||
while (level < currentPath.length - 1) { | ||
currentPath.pop() | ||
} | ||
if (isFile) { | ||
// Current Line is a file, add it to the files array (denoted by "_") | ||
currentPath[level]._ ??= [] | ||
currentPath[level]._.push(name) | ||
} else { | ||
const dir = name.replace("/", "") | ||
// Current Line is a folder, create a new object and update the currentPath | ||
currentPath[level][dir] ??= {} | ||
currentPath.push(currentPath[level][dir]) | ||
} | ||
}) | ||
return root | ||
} | ||
const txt = props.body?.trim() || '' | ||
const files = parseFileStructure(txt) | ||
</script> |
Oops, something went wrong.