diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..81f2493 --- /dev/null +++ b/.gitignore @@ -0,0 +1,196 @@ +# Created by https://www.gitignore.io/api/node,python,sublimetext + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +### SublimeText ### +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + + +# End of https://www.gitignore.io/api/node,python,sublimetext \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 4901de1..0000000 --- a/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Ghost on Github Pages -![Ghost is an awesome open-source blogging plataform. Now you can host it for free at Github Pages.](http://i.imgur.com/3ACSCiW.jpg) -![Ghost is an awesome open-source blogging plataform. Now you can host it for free at Github Pages.](https://cloud.githubusercontent.com/assets/120485/6626501/b2bb072c-c8ff-11e4-8e1a-2e78e68fd5c3.png) - -[Ghost](https://github.com/tryghost/Ghost) is a simple, powerful publishing platform that allows you to share your stories with the world. It usually needs a paid host, but there's some ways to host your Ghost installation at Github Pages, for free. - -In order to create your own Ghost blog for free and host it at Github pages, check the following instructions. These instructions were tested within Linux, if you know how to make it work for Windows or Mac OS, please let me know and I'll add the instructions here. [**Check out the Live Demo**](https://github.com/paladini/paladini.github.io). - -**Note:** that the first time installation take some time (about 10 minutes), but after that you just need to run `npm start` to use Ghost at your computer (creating posts, modifying the website, etc.) and `./update_website.sh` to send the changes to your website. Simple as that. - -## Prerequisites -Before we start, you need to install some prerequisites: -- [**pip**](https://pip.pypa.io/en/stable/quickstart/): Python 2.7.9 and later comes with *pip* by default, so it won't will bother you. -- [**buster**](https://pypi.python.org/pypi/buster/0.1.3): a Python package. -- [**NodeJS**](https://nodejs.org/en/): make sure that your [NodeJS version is officially supported by latest Ghost release](http://support.ghost.org/supported-node-versions/). -- [**npm**](https://nodejs.org/en/): NodeJS package manager. -- [**knex-migrator**](https://github.com/TryGhost/knex-migrator): you will also need to run `knex-migrator init` - -## Installing for the first time -#### 1) Download the latest version of Ghost at [Ghost download page](https://ghost.org/developers/). -![Download the latest version of Ghost](http://i.imgur.com/eO6a2UR.png) - -#### 2) Extract it somewhere you'll remember. In my example, at `/home/paladini/ghost`. -![Extract the Ghost folder somewhere you'll remember](http://i.imgur.com/wFx9uEu.png) - -#### 3) Open the Terminal and navigate to the extracted folder. Run `npm install`. -![Run "npm install". This step will take several minutes.](http://i.imgur.com/jUBPv3h.png) - -#### 4) Now we've Ghost installed. Let's start it's localhost server running `npm start`: -![Run the Ghost server at localhost for the first time using "npm start"](http://i.imgur.com/m49izT3.png) - -#### 5) Ghost now will be live at [http://localhost:2368](http://localhost:2368). Let's create your user and configure Ghost for the first time: go to [http://localhost:2368/ghost](http://localhost:2368/ghost) and follow the instructions. -![Follow the Ghost instructions for the first time install.](http://i.imgur.com/lss8Rbw.png) - -#### 6) Now you are at the Ghost Administrative Panel, personalize your page and create the desired content. -![Ghost Administrative Panel](http://i.imgur.com/lXhbMJK.png) - -#### 7) Go to [Github.com](http://www.github.com) and create a repository called `YOUR_USERNAME.github.io` (in my case it was [paladini.github.io](http://paladini.github.io)). -![Create a repository called "YOUR_USERNAME.github.io".](tutorial_images/ghost-at-github-create-repository.png) - -#### 8) Download [this script](https://github.com/paladini/ghost-for-github-pages/blob/master/update_website.sh) and [this HTML page](https://raw.githubusercontent.com/paladini/ghost-on-github-pages/master/index.html) and put it inside Ghost folder. Open a terminal window, go the Ghost folder and run `chmod +x update_website.sh`. -![](tutorial_images/ghost-at-github-pages-for-free-index-script.png) - -#### 9) Open another Terminal window and go to Ghost folder (in my case: `/home/paladini/ghost`). Run the following commands: - -```sh -buster setup -buster generate -git init -git remote add origin git@github.com:YOUR_USERNAME/YOUR_USERNAME.github.io.git -git add -A -git commit -m "First commit" -git push origin master -f -``` - -#### 10) After about 10 minutes (according to Github Pages), your website will be live at [http://YOUR_USERNAME.github.io](http://YOUR_USERNAME.github.io). In my case, this is my page: -![](tutorial_images/ghost-at-github-pages-7.png) - -## Updating the website [creating new posts, changing theme, etc.] -Whenever you want to create a new post, change the theme of the site (etc.), you should run `npm start` inside the Ghost folder to start the server at the localhost. Then you can go to [http://localhost:2368/ghost/](http://localhost:2368/ghost/) and do whatever you want to. - -To send the changes to your page, just run `./update_website.sh` from the Terminal. Remember that Github takes about 10 minutes to update the website. - -## About -This readme was created in less than one hour, so if it have any problems or you has some question in some topic, please contact me at fernandopalad at gmail dot com. Feel free to improve it or make any critics. - -**References:** -- http://ledtechnica.com/free-ghost-hosting-on-github-pages/ diff --git a/includes/deploy.sh b/includes/deploy.sh new file mode 100644 index 0000000..143e53c --- /dev/null +++ b/includes/deploy.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +HOME_PATH=$HOME +GHOST_PATH="${HOME_PATH}/.ghost/current" +GHOST_SERVER_URL="localhost:2373/" + +first_deploy() { + if [ -d "$GHOST_PATH" ]; then + cd "$GHOST_PATH" + + # Expects an input from user to provide a Git remote URL in which Ghost will be deployed. + echo ' -------------------- INFORMATION NEEDED -------------------- ' + echo '' + echo "Following you'll be asked to enter a Git Remote URL in which you would like to deploy Ghost." + echo "Example:" + echo " git@github.com:YOUR_USERNAME/YOUR_REPOSITORY.git" + echo '' + read -p "Remote URL: " remote_url + + # Setting up buster on the current folder. + buster setup --gh-repo="$remote_url" + buster generate --domain="$GHOST_SERVER_URL" + + git init + git remote add origin "$remote_url" + + # Add .gitignore + if [ -f "gitignore.base" ]; then + $(rm -f .gitignore) + $(cp gitignore.base .gitignore) + fi + + git add -A + git commit -m "First commit on Github Pages using Ghost." + git push origin master:master master:gh-pages -f + fi +} + +update() { + if [ -d "$GHOST_PATH" ]; then + cd "$GHOST_PATH" + + # Generating static files + buster generate --domain="$GHOST_SERVER_URL" + + # Commiting changes to repository in order to deploy new content. + git add -A + git commit -m "Update on the website at $(date)" + git push origin master:master master:gh-pages -f + fi +} + +deploy() { + if [ -d "$GHOST_PATH" ]; then + cd "$GHOST_PATH" + + # Check if repo already exists on current path + repo_exists="$(git status)" + case "fatal" in + *"$repo_exists"*) + echo '[INFO] Configuring git repository...' + echo '[INFO] Generating static files from Ghost server...' + first_deploy + exit + ;; + esac + echo '[INFO] Deploying to your Github repository...' + update + fi +} +deploy + + diff --git a/includes/gitignore.base b/includes/gitignore.base new file mode 100644 index 0000000..81f2493 --- /dev/null +++ b/includes/gitignore.base @@ -0,0 +1,196 @@ +# Created by https://www.gitignore.io/api/node,python,sublimetext + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +### SublimeText ### +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + + +# End of https://www.gitignore.io/api/node,python,sublimetext \ No newline at end of file diff --git a/index.html b/includes/index.html similarity index 100% rename from index.html rename to includes/index.html diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..7c78f16 --- /dev/null +++ b/install.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +RELATIVE_PATH=$(dirname "$0") +GHOST_ZIP=includes/latest_ghost_release.zip +HOME_PATH=$HOME +GHOST_PATH="${HOME_PATH}/.ghost/" + +# Operating system specific instructions +if [ "$(uname -s)" = 'Linux' ]; then + CURRENT_SCRIPT_PATH=$(readlink -f "$0") +else + CURRENT_SCRIPT_PATH=$(readlink "$0") +fi +CURRENT_FOLDER_PATH=$(dirname "$CURRENT_SCRIPT_PATH") + +check_ghost_folder() { + if [ ! -d "includes/ghost" ]; then + echo '[ERROR] Ghost not found at includes/ghost!!! Exiting...' + exit + fi +} + +local_setup() { + if [ -d "$GHOST_PATH" ]; then + echo '[INFO] Ghost already installed at' "$GHOST_PATH" + else + echo '[INFO] Installing Ghost-CLI...' + mkdir -p "$GHOST_PATH" + cd "$GHOST_PATH" + + # Installing Ghost CLI + npm i -g ghost-cli@latest + + # Installing local version of Ghost + echo '[INFO] Trying to install Ghost using Ghost-CLI...' + echo '[INFO] Installing Ghost at' "$GHOST_PATH" + ghost install local --no-start --enable + fi + # echo '[INFO] Finished!' +} + +move_includes() { + if [ ! -d "includes/" ]; then + cd "$RELATIVE_PATH" + fi + $(cp includes/deploy.sh "$GHOST_PATH/") + $(cp includes/deploy.sh "$GHOST_PATH""/current/") + $(cp includes/index.html "$GHOST_PATH""/current/") + $(cp includes/gitignore.base "$GHOST_PATH""/current/") + $(cp includes/gitignore.base "$GHOST_PATH""/current/.gitignore") + $(chmod +x "$GHOST_PATH""/deploy.sh") +} + +local_deps() { + echo '[INFO] Installing needed dependencies...' + + cd "$GHOST_PATH" + success=0 + check_pip=$(which pip) + check_pip2=$(which pip2) + check_pip27=$(which pip2.7) + + if [ "$check_pip" ]; then + pip install buster + success=`expr $success + 1` + else + echo "[INFO] Command 'pip' was not found on path..." + fi + + if [ "$check_pip2" ]; then + pip2 install buster + success=`expr $success + 1` + else + echo "[INFO] Command 'pip2' was not found on path..." + fi + + if [ "$check_pip27" ]; then + pip2.7 install buster + success=`expr $success + 1` + else + echo "[INFO] Command 'pip2.7' was not found on path..." + fi + + # Checking if pip was found and 'buster' was successfully installed. + if [ "$success" -eq "0" ]; then + echo "[WARN] Command pip cannot be found on your system." + echo "[WARN] Trying to install pip for Python 2..." + + # Trying to install pip for different OSs (MacOS and Linux) + if [ "$(uname)" == "Darwin" ]; then + echo '[INFO] Mac OS detected.' + sudo easy_install pip + sudo pip install --upgrade virtualenv + sudo pip install buster + elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + echo '[INFO] Linux detected.' + sudo apt-get install python-setuptools python-dev build-essential + sudo easy_install pip + sudo pip install --upgrade virtualenv + sudo pip install buster + else + echo '[ERROR] Operating System not supported yet. Please, open a Github Issue at https://github.com/paladini/ghost-on-github-pages/issues telling about this problem.' + echo "[ERROR] Since 'pip' for Python 2 and 'buster' was not found and cannot be installed, I'm exiting this installation script now." + exit + fi + fi + + # echo '[INFO] pip and Buster packages were successfully installed.' + echo '[INFO] Done! Dependencies appears to be okay.' +} + +local_run() { + if [ -d "$GHOST_PATH" ]; then + echo '[INFO] Starting Ghost server...' + cd "$GHOST_PATH" + ghost start --enable + fi +} + +local_setup +local_deps +local_run +move_includes + +(cd "$GHOST_PATH" && ./deploy.sh) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..ba44713 --- /dev/null +++ b/readme.md @@ -0,0 +1,119 @@ +# Ghost on Github Pages + +![image](https://user-images.githubusercontent.com/3361224/39667855-7f37e624-5095-11e8-9297-6a2e63aaac4b.png) + +[Ghost](https://github.com/tryghost/Ghost) is a fully open source, adaptable platform for building and running a modern online publication - a complete professional publishing platform. **Now you can build your own Ghost blog for free in a few minutes.** After that initial setup, it's very easy to maintain a fresh and modern blog. + +