A template for DocFxMarkdownGen and Docusaurus. This repository also contains GitHub Actions workflows for automatic documentation generation and deployment to Vercel(just my preference, any should work).
dotnet tool install -g DocFxMarkdownGen
# to update
dotnet tool update -g DocFxMarkdownGen
# * docfx can also be installed as a .NET tool:
dotnet tool install -g docfxIf a message telling you to add dotnet tools to your PATH after install comes up, do as it says. You should now be able to use the dfmg command.
Replace dfmg-docs with your desired project name.
yarn create docusaurus dfmg-docs https://github.com/Jan0660/dfmg-template2.gitThe following steps count with the project you are generating documentation being in ../Project:
- Update
.env:PROJECT_REPOto your project's repository, e.g.Jan0660/Project.PROJECT_NAMEto your .NET project name.PROJECT_BRANCHto the branch you want to generate documentation for.
- In
docfx.jsonchangeProjectto yourPROJECT_NAMEyou set in.envearlier and also check "src" matches your project structure. - Do the following for the workflows in
.github/workflows/if you wish to keep them:-
If you are targeting a framework > .NET 6 you need to add another "Setup .NET Core SDK" step after the one that install .NET 6, for example:
- name: Setup .NET Core SDK uses: actions/setup-dotnet@v3 with: dotnet-version: 6.0.x - name: Setup .NET 7 SDK uses: actions/setup-dotnet@v3 with: dotnet-version: 7.0.x
-
If different, change
mainto your main/production branch name(of the documentation repository). -
For Vercel, set up the secrets (one of the passages here will help you).
-
For GitHub Pages, it seems you have to do this for it to work.
-
Done! All you need to do now is to edit docusaurus.config.js to suit your project and generate api documentation with the generate.sh script.
For keeping multiple versions of the generated documentation you can set the VERSIONS variable in .env to something like this:
# multiple items would be like VERSIONS=("0.1.0;v0.1.0" "0.2.0;v0.2.0")
VERSIONS=("0.1.0;v0.1.0")And generate.sh will take care of the rest(provided your project is structure like this template).
The part before the semicolon is the version name in docusaurus and the part after is the git tag. You can add as many as you want, just separate them with a space.
If you kept the GitHub Actions you will need extra setup so that your documentation updates when you push to your .NET project.
- on the .NET repository:
-
set up a personal access token with with access to your documentation repository, and set it as a secret named
PAT_TOKEN. Also setPAT_USERNAMEas your username. -
Add the following workflow to
.github/workflows/. ReplaceYOURNAMEwith your GitHub username andREPONAMEwith your documentation repository name.name: Update Documentation on: push: branches: - main jobs: update: runs-on: ubuntu-latest steps: - name: Trigger Documentation Update (preview-deploy-vercel) run: | curl -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/YOURNAME/REPONAME/actions/workflows/preview-deploy-vercel.yaml/dispatches --data '{"ref": "master"}'
-
Cheers! Now whenever you push to your .NET project, the documentation will be updated.
-
- Everything should be set up already on the documentation repository, since
on.workflow_dispatchis already set up in.github/workflows/preview-deploy-vercel.yaml.
- Clone this repository.
yarn installyarn start
-
Get .NET 6.0
-
Install the needed .NET tools. If a message telling you to add dotnet tools to your
PATHafter install comes up, do as it says.dotnet tool install -g DocFxMarkdownGen # * docfx can also be installed as a .NET tool: dotnet tool install -g docfx # to update these: dotnet tool update -g 'toolname'
-
Clone Project.
-
Clone this repository and
cdinto it.Projectshould now be at../Project. -
Run
generate.shto generate the API documentation. You need bash for this. -
yarn install -
yarn start -
Done.