Skip to content
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

Merged
merged 3 commits into from
Nov 15, 2021

Conversation

afshinm
Copy link
Contributor

@afshinm afshinm commented Sep 17, 2020

Motivation

This PR enables users to provide a custom init template. It searches the local ./templates folder in addition to docusaurus-init/templates.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Screenshot 2020-09-17 at 14 55 12

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.)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Sep 17, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Sep 17, 2020

✔️ [V2]
Built without sensitive environment variables

🔨 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'))
Copy link
Contributor

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

Copy link
Contributor Author

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.

@slorber
Copy link
Collaborator

slorber commented Sep 29, 2020

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?
Do you need to create your own template to start multiple docusaurus sites (afaik only Facebook has this need currently, as a heavy Docusaurus user)?
Then instead of a folder convention, why not providing the template path as a cli arg directly?

@afshinm
Copy link
Contributor Author

afshinm commented Sep 29, 2020

@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 docusaurus-init implementation doesn't allow me to pass a folder in the CLI args (it only accepts valid git URLs or default docusaurus-init templates that are predefined here https://github.com/facebook/docusaurus/tree/master/packages/docusaurus-init/templates).

My PR changes this logic a bit so that users can provide the initial template using either:

@slorber
Copy link
Collaborator

slorber commented Sep 29, 2020

I'd like to use those templates to initiate my Docusaurus site.

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:

  • Ability to run npx @docusaurus/init@next init ./templates/myCustomTemplate

  • A new "Custom template folder" option in the select list below

image

@afshinm
Copy link
Contributor Author

afshinm commented Sep 29, 2020

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?

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)

Ability to run npx @docusaurus/init@next init ./templates/myCustomTemplate

That makes sense. I'm happy to update the PR to reflect that change.

A new "Custom template folder" option in the select list below

Good idea, I like that.

@slorber
Copy link
Collaborator

slorber commented Sep 29, 2020

Great, tell me when it's ready ;)

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)

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.

@slorber slorber marked this pull request as draft September 30, 2020 15:58
@github-actions
Copy link

github-actions bot commented Nov 15, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 72
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-3458--docusaurus-2.netlify.app/

Copy link
Collaborator

@Josh-Cena Josh-Cena left a 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

@Josh-Cena Josh-Cena marked this pull request as ready for review November 15, 2021 04:25
@Josh-Cena Josh-Cena changed the title feat(docusaurus-init): search the local ./templates folder during doc init feat(create-docusaurus): allow using local folder as template Nov 15, 2021
@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Nov 15, 2021
@Josh-Cena Josh-Cena merged commit 54d0755 into facebook:main Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants