diff --git a/.gitignore b/.gitignore index 5396b94a..d5afd046 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ node_modules +.preview diff --git a/README.md b/README.md index 4c6e2017..9d32340b 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ website will not be available. If a commit is meant to be backported to a stable branch, it must be labelled with `backport/v1.20`, `backport/v1.19`, etc. +### Previewing changes + +Run `pnpm run preview` to clone the [website repo](https://codeberg.org/forgejo/forgejo) +and launch a local development server. The current docs branch will be opened in the browser. + +Modifications can be made to the docs while the dev server is running, and the preview will live-reload. + ### Links All internal links within the documentation content should be relative to each page's path diff --git a/package.json b/package.json index 97e9a73a..93737fa6 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "license": "CC-BY-SA-4.0", "private": true, "scripts": { + "preview": "./scripts/preview.sh", "test": "echo \"Error: no test specified\" && exit 1", "lint:remark": "remark . --quiet --frail", "lint:prettier": "prettier --check .", diff --git a/scripts/preview.sh b/scripts/preview.sh new file mode 100755 index 00000000..440df8b4 --- /dev/null +++ b/scripts/preview.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +current_branch=$(git branch --show-current) +repo_path=$(pwd) + +# Clone the website repo, or make sure the current clone is up to date +if [ ! -e "./.preview" ];then + git clone https://codeberg.org/forgejo/website.git .preview + cd .preview +else + cd .preview + git checkout main + git pull +fi + +# make sure the docs content of the website is up to date +git submodule update --remote + +# install the website dependencies +pnpm install + +# symlink the current docs branch from the website content repo +rm -rf ./src/content/docs/$current_branch +mkdir -p $(dirname ./src/content/docs/$current_branch) # in case of branch names with slashes +ln -s $repo_path/docs/ ./src/content/docs/$current_branch + +rm -rf ./public/images/$current_branch +mkdir -p $(dirname ./src/content/images/$current_branch) # in case of branch names with slashes +ln -s $repo_path/images/ ./public/images/$current_branch + +# once the dev server is running, open the current docs branch in the browser +sleep 3 && open http://localhost:3000/docs/$current_branch/ & + +# start the dev server +pnpm run dev