Last active
January 4, 2021 04:41
-
-
Save gustiando/209da343a168c34320e1bb59d3508c60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
################################################################################################################ | |
# | |
# This script will quickly set you up with Github Pages and jrnl to get you up and running journaling online for | |
# whatever your purpose is. | |
# | |
# How to run: `source one-step-to-journal.sh && bootstrap_github_journal_page` | |
# | |
# A few things to note: | |
# 1. Currently only supports MacOS | |
# 2. It uses the current directory to create the new repo. | |
# | |
# Cronjob: | |
# Adding the following in your crontab file can automatically publish posts daily if desired. | |
# | |
# ``` | |
# PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin | |
# 0 0 * * * cd ~/Workspace && source one-step-to-journal.sh && publish_to_github_pages | |
# ``` | |
################################################################################################################ | |
GITHUB_USER_NAME=`cat ~/.config/gh/hosts.yml | sed -n "/user/p" | sed "s/.*user: \(.*\)/\1/"` | |
GITHUB_REPO_NAME=$GITHUB_USER_NAME.github.io | |
WORKSPACE_DIR=`pwd` | |
GH_PAGE_REPO=$WORKSPACE_DIR/$GITHUB_REPO_NAME | |
function publish_to_github_pages() { | |
echo "Publishing local journal updates to Github Pages...\n" | |
cd $GH_PAGE_REPO | |
jrnl --format md > $GH_PAGE_REPO/index.md | |
git add -A | |
git commit -m "Update journal entries" | |
git push --force --set-upstream origin master | |
echo "\nDone! The newest updates should be up shortly.\n" | |
} | |
function bootstrap_github_journal_page() { | |
echo "Installing journal program...\n" | |
brew install jrnl | |
echo "\nInstalling Github CLI program... Please follow its authentication instructions carefully.\n" | |
brew install gh | |
gh auth login | |
echo "Creating repository for Github Pages..." | |
gh repo create -y $GITHUB_REPO_NAME | |
cd $GH_PAGE_REPO | |
echo $GITHUB_REPO_NAME > README.md | |
echo "theme: minima" > _config.yml | |
publish_to_github_pages | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment