-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(content): pass document data to remark plugins (#782)
- Loading branch information
Showing
7 changed files
with
156 additions
and
4 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
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,16 @@ | ||
<template> | ||
<ul> | ||
<li v-for="item in items" :key="item">{{ item }}</li> | ||
</ul> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
items: { | ||
type: Array, | ||
default: () => [] | ||
} | ||
} | ||
} | ||
</script> |
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,9 @@ | ||
--- | ||
title: Auto generated authors list | ||
|
||
--- | ||
|
||
Authors list: | ||
|
||
|
||
<authors /> |
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,16 @@ | ||
<template> | ||
<div> | ||
<nuxt-content :document="markdown" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default { | ||
async asyncData ({ $content }) { | ||
const markdown = await $content('authors-page').fetch() | ||
return { | ||
markdown | ||
} | ||
} | ||
} | ||
</script> |
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,26 @@ | ||
const fetch = require('node-fetch') | ||
|
||
module.exports = function () { | ||
return async (tree, file) => { | ||
let filePath | ||
tree.children = tree.children.map((node) => { | ||
const TAG_REGEX = /\s*<(authors)\s*/i | ||
if (node.type === 'html' && node.value.match(TAG_REGEX)) { | ||
filePath = 'README.md' // detect file path | ||
node.value = node.value.replace(TAG_REGEX, '<$1 :items="$authors" ') | ||
} | ||
return node | ||
}) | ||
if (filePath) { | ||
const commits = await fetch( | ||
'https://api.github.com/repos/nuxt/content/commits?path=' + filePath | ||
).then(res => res.json()) | ||
const authors = commits | ||
.map(commit => commit.author.login) | ||
.filter(Boolean) | ||
|
||
file.data.$authors = [...new Set(authors)] | ||
} | ||
return tree | ||
} | ||
} |
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