-
-
Notifications
You must be signed in to change notification settings - Fork 9k
feat(create-docusaurus): allow using local folder as template #3458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(create-docusaurus): allow using local folder as template #3458
Conversation
✔️ [V2] 🔨 Explore the source changes: db87c78 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6191e0bd4f83ec00082c2873 😎 Browse the preview: https://deploy-preview-3458--docusaurus-2.netlify.app |
templates, | ||
...fs | ||
.readdirSync(templatesDir) | ||
.filter((d) => !d.startsWith('.') && !d.startsWith('README')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, good idea!
I'm curious, Why do you have a filter for directories that starts with readme? !d.startsWith('README')
?
maybe would be good add a option in the docusaurus.config.js
to not restrict only to the current directory.
Also in case of approved, it was good have a section in the documentation https://v2.docusaurus.io/docs/next/installation#scaffold-project-website
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fanny thanks! Appreciate your feedback.
readdirSync
lists all directories and files in a folder (including README
and .
). That condition is in place to make sure directories are only added to the probe list. Also, I didn't add that condition in my PR, that condition was already in place. I just refactored it into a separate function.
Sounds good! I'm happy to update the docs as well.
Hey. The feature seems implemented correctly but I'm not sure to understand the purpose of this feature in the first place. Who would use this, and why? |
@slorber So I have some custom templates (docusaurus-init templates, like this one https://github.com/facebook/docusaurus/tree/master/packages/docusaurus-init/templates/classic). I'd like to use those templates to initiate my Docusaurus site. The current My PR changes this logic a bit so that users can provide the initial template using either:
|
But why do you need templates if you just want one Docusaurus site? Can't you just modify the site after it being initialized with an existing template? I don't like the idea of having a local folder with templates, as it's an unnecessary constraint of using this feature and force the user to put templates in a specific location. Instead I'd like this:
|
Well I definitely can but it's very error-prone and requires me to write additional scripts just to clean up the state and the doc is initiated (e.g. I'd like to change the default README.md file)
That makes sense. I'm happy to update the PR to reflect that change.
Good idea, I like that. |
Great, tell me when it's ready ;)
From your text, it seems like you only needed one site, that's why I wonder why you need templates. If you need only 1 site you likely don't need scripts either. So my guess is you actually need multiple sites with some shared attributes (like a modified readme), and just curious about your usecase for having this need. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3458--docusaurus-2.netlify.app/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this. I think it's good for now, doubt if many people use the git repo feature anyways
Motivation
This PR enables users to provide a custom init template. It searches the local
./templates
folder in addition todocusaurus-init/templates
.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Also happy to write some tests for this particular usecase.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)