Writing a Website using Quarto
Creating a Web Project
A web project can be created by using Quarto CLI tool. A web project consists of the following files:
_quarto.yml
– the main config file of the Quarto projectindex.qmd
– the main page of the web projectstyles.css
– contains style information
You can render and view the website locally using quarto preview
command.
Read more from Quarto Web Project.
Publishing Website on Github
There are mainly two ways to publicize your website on Github:
- Render the website locally and publish it to a Github Repo. This is a preferred when you don’t need to run your code on Github. (See the following section about rendering the website locally)
- Render the website using Github Action. By doing so, you don’t need to run your code locally. Everything is managed by Github Action.
The rendered website will be accessble under https://<your-username>.github.io/<repository-name>
.
More information can be found from the original tutorial.
Render the Website locally
Set up a Github repository. Assume your workspace is on the
main
branch.Exclude Quarto related files (
/.quarto/
and/_site/
) from the version control by adding them in a.gitignore
file.Check the configurations in “Settings -> Pages” of your Github:
- the site directory is set to the repository root (
/
) - the source branch for your repository is
gh-pages
- the site directory is set to the repository root (
Commit your code!
Make an initial empty push to the remote
gh-pages
branch:git checkout --orphan gh-pages git reset --hard # make sure all changes are committed before running this! git commit --allow-empty -m "Initialising gh-pages branch" git push origin gh-pages
Check out to your main branch:
git checkout main
Publish to the new branch:
quarto publish gh-pages
Publishing Website using Github Action
If you would like to execute your code locally before pushing to Github, you can follow this tutorial. This can be useful if you would like to include result from a legacy code.
You can also instead let Github Action run the code and publish the website all at once, thus you can follow this tutorial.
Include a Link to your Github Repository
There are related html options for this purpose. More information can be found in the official guide.
Customize 404 Page
You can create your own page for handling 404 error. In many cases a 404.qmd
file is all what you need. More information can be found in the official guide.