vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.36k stars 923 forks source link

[Feature request] Support vue js ts file as pages #1607

Closed Mister-Hope closed 1 month ago

Mister-Hope commented 2 months ago

Clear and concise description of the problem

Generally, .vue and component with .js .ts could all be pages, so we can make vuepress support them out of box, while remaining the default pagesPattern to be only markdown.

Suggested solution

A vue component:

<script setup>
// ...
</script>

<frontmatter lang="yaml">
title: asd
description: asd
</frontmatter>

<template>
  <!-- content -->
</template>

The lang="yaml" is the default behavior, so we can make it optional, but declaring it provides volar with correct highlighting and formatting, we can also support lang='json'

For js and ts component, a frontmatter named export is preferred:

export const frontmatter = {
 // ...
}

export default defineComponent({
 // ...
})
meteorlxy commented 2 months ago

The page creation is based on markdown, and we extract page data by the markdown parser. If we want to support vue / ts pages, we need to parse the vue file / ts file when creating the page to keep the current process.

That means:

It might be ok if we skip the normal page creation process for vue / ts pages. However, I think this feature makes little sense for common users. Only some advance users might need this. IMO, no exceptions should be made for these rare cases.

In addition, for advanced users, they could already add pages via vue / ts by adding a custom Layout & node API.

Thus, I'm not in favor of adding extra complexity to this kind of feature that already has a way of being implemented.

If it's really a common use case, we can consider providing some method / utils to help adding pages programmatically

github-actions[bot] commented 2 months ago

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.