feat(theme-docs): support a way to ignore some contents
See original GitHub issueIs your feature request related to a problem? Please describe.
I’m creating a static doc site on the top of content-theme-docs
, which will have many page eventually.
For now, some pages are completed and ready to be published, while other markdown files are being written.
I decided to publish the doc site with some pages at first, and looked for a way to exclude or hide work-in-progress contents.
But, I don’t want to move such files to other directory because then I can’t access them in the doc site with yarn run dev
.
I just want work-in-progress pages to be excluded from production build and generate.
At first, I tried ignore
option and generate.exclude
option like below but I found that they cannot prevent contents from being added to database and rendered in the sidebar.
{
ignore: process.env.NODE_ENV === 'production' ? [ /^\/sample\/.*/ ] : []
}
{
generate: {
exclude: process.env.NODE_ENV === 'production' ? [ /^\/sample\/.*/ ] : []
}
}
Secondly, I tried to do something on database
in content:file:beforeInsert
hook, but I couldn’t do anything because the files that I want to be excluded namely had not yet inserted.
FYI: As I described in #576, theme-docs replaces user’s content:file:beforeInsert
hook. So I modified the installed @nuxt/content
’s file directly to test it.
As far as I read parts of code related to database, it ignores node_modules
and hidden files whose name begin with .
by default. So, I guess it’s possible to add a logic here to ignore some contents.
Describe the solution you’d like
Adding either content.ignore
or content.exclude
which is an array of regular expressions will be so nice, in that they align with ignore
and generate.exclude
options.
{
content: {
ignore: process.env.NODE_ENV === 'production' ? [ '**/wip.md' ] : [ ]
}
}
Describe alternatives you’ve considered
Adding content.dirs
which is an array of paths would be also possible. In this case, we can dynamically include or exclude directory for work-in-progress pages, for example, based on process.env.NODE_ENV
.
{
content: {
dirs: process.env.NODE_ENV === 'production' ? [ 'content' ] : [ 'content', 'content-wip' ]
}
}
But, we have to resolve conflict between content.dir
and content.dirs
.
Additional context
Although I’m not so familiar with the database-related parts of code, I will give it a try to implement this feature and submit a draft PR, so that we can discuss this feature in more detail. 🙋
Thank you for reading so long message. 🙇
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (4 by maintainers)
Top GitHub Comments
I believe this has been addressed in v2 where you can mark a document as: draft, partial or ignore it.
I came up with another idea: setting a flag like
publish: true/false
in the front matter. This would be more blog-like DX rather than documentation, but the way is much easier than defining patterns to match.