├── .github └── workflows │ └── main.yml ├── README.md ├── deploy.sh └── site.toml /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Publish Notion website to GitHub Pages 2 | 3 | on: 4 | # Manual update only. 5 | workflow_dispatch: 6 | 7 | permissions: 8 | contents: write 9 | 10 | jobs: 11 | deploy: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout loconotion 15 | uses: actions/checkout@v3 16 | with: 17 | repository: leoncvlt/loconotion 18 | path: loconotion 19 | - name: Checkout this repo 20 | uses: actions/checkout@v3 21 | with: 22 | path: pages_repo 23 | - name: Download and install chromedriver 24 | run: sudo apt install chromium-chromedriver 25 | - name: Install Loconotion dependencies 26 | run: pip install -r loconotion/requirements.txt 27 | - name: Run Loconotion 28 | run: | 29 | python3 loconotion/loconotion --chromedriver chromedriver "pages_repo/site.toml" 30 | - name: Push to GitHub pages 31 | run: | 32 | git config --global user.name "github-actions[bot]" 33 | git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" 34 | GIT_DEPLOY_DIR=../dist/site \ 35 | GIT_DEPLOY_BRANCH=gh-pages \ 36 | GIT_DEPLOY_REPO="https://${{ github.token }}@github.com/${{ github.repository }}.git" ./deploy.sh 37 | working-directory: pages_repo 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notion website template 2 | 3 | Make a website using Notion, GitHub Pages and Loconotion in just 5 steps. 4 | 5 | 1. Fork this repo or press [use this template button](https://github.com/timovv/notion-website-template/generate). 6 | 1. Create a Notion page to be your website. This can have subpages, databases, anything supported by [Loconotion](https://github.com/leoncvlt/loconotion). 7 | 1. Share your Notion page publicly, and update `site.toml` in your repo to point to it. 8 | 1. Run the `Publish Notion website to GitHub Pages` action under the Actions tab of your repo. 9 | 1. Update your repo's `Pages` settings to use the `gh-pages` branch, hit save, and voila! 10 | 11 | To resync the website, simply run the GitHub action again. `site.toml` can be updated to use any of the settings specified in the [Loconotion README](https://github.com/leoncvlt/loconotion/blob/master/README.md). 12 | 13 | ## Acknowledgements 14 | 15 | Thanks to: 16 | - @leoncvt for creating the Loconotion script 17 | - @X1011 for the original script used to deploy the website to GitHub pages -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Originally obtained from https://github.com/X1011/git-directory-deploy, with thanks to the author. 4 | # Used under the BSD 3-Clause License, reproduced below: 5 | # 6 | # BSD 3-Clause License: 7 | # 8 | # Copyright Daniel Smith 9 | # All rights reserved. 10 | # 11 | # Redistribution and use in source and binary forms, with or without modification, 12 | # are permitted provided that the following conditions are met: 13 | # 14 | # Redistributions of source code must retain the above copyright notice, this 15 | # list of conditions and the following disclaimer. 16 | # 17 | # Redistributions in binary form must reproduce the above copyright notice, this 18 | # list of conditions and the following disclaimer in the documentation and/or 19 | # other materials provided with the distribution. 20 | # 21 | # The names of the contributors may not be used to endorse or promote products 22 | # derived from this software without specific prior written permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | set -o errexit #abort if any command fails 36 | me=$(basename "$0") 37 | 38 | help_message="\ 39 | Usage: $me [-c FILE] [] 40 | Deploy generated files to a git branch. 41 | 42 | Options: 43 | 44 | -h, --help Show this help information. 45 | -v, --verbose Increase verbosity. Useful for debugging. 46 | -e, --allow-empty Allow deployment of an empty directory. 47 | -m, --message MESSAGE Specify the message used when committing on the 48 | deploy branch. 49 | -n, --no-hash Don't append the source commit's hash to the deploy 50 | commit's message. 51 | -c, --config-file PATH Override default & environment variables' values 52 | with those in set in the file at 'PATH'. Must be the 53 | first option specified. 54 | 55 | Variables: 56 | 57 | GIT_DEPLOY_DIR Folder path containing the files to deploy. 58 | GIT_DEPLOY_BRANCH Commit deployable files to this branch. 59 | GIT_DEPLOY_REPO Push the deploy branch to this repository. 60 | 61 | These variables have default values defined in the script. The defaults can be 62 | overridden by environment variables. Any environment variables are overridden 63 | by values set in a '.env' file (if it exists), and in turn by those set in a 64 | file specified by the '--config-file' option." 65 | 66 | parse_args() { 67 | # Set args from a local environment file. 68 | if [ -e ".env" ]; then 69 | source .env 70 | fi 71 | 72 | # Set args from file specified on the command-line. 73 | if [[ $1 = "-c" || $1 = "--config-file" ]]; then 74 | source "$2" 75 | shift 2 76 | fi 77 | 78 | # Parse arg flags 79 | # If something is exposed as an environment variable, set/overwrite it 80 | # here. Otherwise, set/overwrite the internal variable instead. 81 | while : ; do 82 | if [[ $1 = "-h" || $1 = "--help" ]]; then 83 | echo "$help_message" 84 | return 0 85 | elif [[ $1 = "-v" || $1 = "--verbose" ]]; then 86 | verbose=true 87 | shift 88 | elif [[ $1 = "-e" || $1 = "--allow-empty" ]]; then 89 | allow_empty=true 90 | shift 91 | elif [[ ( $1 = "-m" || $1 = "--message" ) && -n $2 ]]; then 92 | commit_message=$2 93 | shift 2 94 | elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then 95 | GIT_DEPLOY_APPEND_HASH=false 96 | shift 97 | else 98 | break 99 | fi 100 | done 101 | 102 | # Set internal option vars from the environment and arg flags. All internal 103 | # vars should be declared here, with sane defaults if applicable. 104 | 105 | # Source directory & target branch. 106 | deploy_directory=${GIT_DEPLOY_DIR:-dist} 107 | deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages} 108 | 109 | #if no user identity is already set in the current git environment, use this: 110 | default_username=${GIT_DEPLOY_USERNAME:-deploy.sh} 111 | default_email=${GIT_DEPLOY_EMAIL:-} 112 | 113 | #repository to deploy to. must be readable and writable. 114 | repo=${GIT_DEPLOY_REPO:-origin} 115 | 116 | #append commit hash to the end of message by default 117 | append_hash=${GIT_DEPLOY_APPEND_HASH:-true} 118 | } 119 | 120 | main() { 121 | parse_args "$@" 122 | 123 | enable_expanded_output 124 | 125 | commit_title=`git log -n 1 --format="%s" HEAD` 126 | commit_hash=` git log -n 1 --format="%H" HEAD` 127 | 128 | #default commit message uses last title if a custom one is not supplied 129 | if [[ -z $commit_message ]]; then 130 | commit_message="publish: $commit_title" 131 | fi 132 | 133 | #append hash to commit message unless no hash flag was found 134 | if [ $append_hash = true ]; then 135 | commit_message="$commit_message"$'\n\n'"generated from commit $commit_hash" 136 | fi 137 | 138 | previous_branch=`git rev-parse --abbrev-ref HEAD` 139 | 140 | if [ ! -d "$deploy_directory" ]; then 141 | echo "Deploy directory '$deploy_directory' does not exist. Aborting." >&2 142 | return 1 143 | fi 144 | 145 | # must use short form of flag in ls for compatibility with OS X and BSD 146 | if [[ -z `ls -A "$deploy_directory" 2> /dev/null` && -z $allow_empty ]]; then 147 | echo "Deploy directory '$deploy_directory' is empty. Aborting. If you're sure you want to deploy an empty tree, use the --allow-empty / -e flag." >&2 148 | return 1 149 | fi 150 | 151 | if git ls-remote --exit-code $repo "refs/heads/$deploy_branch" ; then 152 | # deploy_branch exists in $repo; make sure we have the latest version 153 | 154 | disable_expanded_output 155 | git fetch --force $repo $deploy_branch:$deploy_branch 156 | enable_expanded_output 157 | fi 158 | 159 | # check if deploy_branch exists locally 160 | if git show-ref --verify --quiet "refs/heads/$deploy_branch" 161 | then incremental_deploy 162 | else initial_deploy 163 | fi 164 | 165 | restore_head 166 | } 167 | 168 | initial_deploy() { 169 | git --work-tree "$deploy_directory" checkout --orphan $deploy_branch 170 | git --work-tree "$deploy_directory" add --all 171 | commit+push 172 | } 173 | 174 | incremental_deploy() { 175 | #make deploy_branch the current branch 176 | git symbolic-ref HEAD refs/heads/$deploy_branch 177 | #put the previously committed contents of deploy_branch into the index 178 | git --work-tree "$deploy_directory" reset --mixed --quiet 179 | git --work-tree "$deploy_directory" add --all 180 | 181 | set +o errexit 182 | diff=$(git --work-tree "$deploy_directory" diff --exit-code --quiet HEAD --)$? 183 | set -o errexit 184 | case $diff in 185 | 0) echo No changes to files in $deploy_directory. Skipping commit.;; 186 | 1) commit+push;; 187 | *) 188 | echo git diff exited with code $diff. Aborting. Staying on branch $deploy_branch so you can debug. To switch back to master, use: git symbolic-ref HEAD refs/heads/master && git reset --mixed >&2 189 | return $diff 190 | ;; 191 | esac 192 | } 193 | 194 | commit+push() { 195 | set_user_id 196 | git --work-tree "$deploy_directory" commit -m "$commit_message" 197 | 198 | disable_expanded_output 199 | #--quiet is important here to avoid outputting the repo URL, which may contain a secret token 200 | git push --quiet $repo $deploy_branch 201 | enable_expanded_output 202 | } 203 | 204 | #echo expanded commands as they are executed (for debugging) 205 | enable_expanded_output() { 206 | if [ $verbose ]; then 207 | set -o xtrace 208 | set +o verbose 209 | fi 210 | } 211 | 212 | #this is used to avoid outputting the repo URL, which may contain a secret token 213 | disable_expanded_output() { 214 | if [ $verbose ]; then 215 | set +o xtrace 216 | set -o verbose 217 | fi 218 | } 219 | 220 | set_user_id() { 221 | if [[ -z `git config user.name` ]]; then 222 | git config user.name "$default_username" 223 | fi 224 | if [[ -z `git config user.email` ]]; then 225 | git config user.email "$default_email" 226 | fi 227 | } 228 | 229 | restore_head() { 230 | if [[ $previous_branch = "HEAD" ]]; then 231 | #we weren't on any branch before, so just set HEAD back to the commit it was on 232 | git update-ref --no-deref HEAD $commit_hash $deploy_branch 233 | else 234 | git symbolic-ref HEAD refs/heads/$previous_branch 235 | fi 236 | 237 | git reset --mixed 238 | } 239 | 240 | filter() { 241 | sed -e "s|$repo|\$repo|g" 242 | } 243 | 244 | sanitize() { 245 | "$@" 2> >(filter 1>&2) | filter 246 | } 247 | 248 | [[ $1 = --source-only ]] || main "$@" -------------------------------------------------------------------------------- /site.toml: -------------------------------------------------------------------------------- 1 | # This is the .toml file passed to Locomotion. 2 | # For information on the different settings available, and an example file, 3 | # see the Locomotion README: https://github.com/leoncvlt/loconotion/blob/master/README.md 4 | 5 | # DO NOT CHANGE THIS VALUE. The deploy script relies on the site being deployed to the 6 | # "site" directory. 7 | name = "site" 8 | 9 | # This page should be the root of your website. It's important. 10 | page = "" 11 | --------------------------------------------------------------------------------