Skip to content

Instantly share code, notes, and snippets.

@mavieth
Last active February 27, 2016 01:34
Show Gist options
  • Select an option

  • Save mavieth/6cc33fd7a73ba6b82efe to your computer and use it in GitHub Desktop.

Select an option

Save mavieth/6cc33fd7a73ba6b82efe to your computer and use it in GitHub Desktop.
Installs Hexo Based Website.
#!/bin/bash
DARKGRAY='\033[1;30m'
RED='\033[0;31m'
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
LIGHTPURPLE='\033[1;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
C='\033[0m' #clean input
SITES=/Users/$(whoami)/sites
# cd $SITES
GITREPO='https://github.com/mavieth/mavieth.github.io.git'
THEME=''
GITUSERNAME='mavieth'
AUTHOR=$(whoami)
function check_hexo_install {
echo "${BLUE}CHECK ${C}Checking for npm package Hexo."
if hash hexo 2>/dev/null; then
echo "${GREEN}SUCCESS ${C}Hexo already installed."
else
npm install hexo-cli -g
fi
}
# Generic Hexo Theme
function install_default_hexo_theme {
cd $SITES/$SITENAME
cd themes/landscape
printf '%s'"
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo
subtitle:
description:
author: $AUTHOR
language: en
timezone:
url: https://$GITUSERNAME.github.io/
root: /
permalink: :title/
permalink_defaults:
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
\n# Posts
new_post_name: :title.md
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: true
tab_replace:
\n# Category & Tag
default_category: uncategorized
category_map:
tag_map:
\n# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
\n# Pagination
## Set per_page to 0 to disable pagination
per_page: 12
pagination_dir: page
theme: $THEME
deploy:
type: git
repo: $GITREPO\n" > _config.yml
}
function get_pages_to_install {
cd $SITES/$SITENAME
allpages="About,Projects,Contact"
IFS=","
for p in $allpages
do hexo new page "$p"
done
# read -p "Add Pages? [yn]: " ans
# if [[ $ans = y ]] ; then
# echo "Enter comma seperated pages to create (Home,About,Contact): "
# read -e allpages
# IFS=","
# for p in $allpages
# do hexo new page "$p"
# done
# fi
allpages="Post1,Post2,Post3,Post4"
IFS=","
for p in $allpages
do hexo new post "$p"
done
# read -p "Add Posts? [yn]: " ans
# if [[ $ans = y ]] ; then
# echo "Enter comma seperated pages to create (Home,About,Contact): "
# read -e allposts
# IFS=","
# for p in $allposts
# do hexo new post "$p"
# done
# fi
clear
}
function setup_parent_config {
printf '%s'"
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo
subtitle:
description:
author: $AUTHOR
language: en
timezone:
url: https://$GITUSERNAME.github.io/
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
\n# Posts
new_post_name: :title.md
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: true
tab_replace:
\n# Category & Tag
default_category: uncategorized
category_map:
tag_map:
\n# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
\n# Pagination
## Set per_page to 0 to disable pagination
per_page: 12
pagination_dir: page
# Hexo Beautify
beautify:
types:
- html
- css
- js
html:
'indent_inner_html': false
'indent_size': 2
'indent_with_tabs': false
# More Options (https://github.com/beautify-web/js-beautify/blob/master/README.md)
css:
'indent_size': 2
'newline_between_rules': true
'indent_with_tabs': false
# More Options (https://github.com/beautify-web/js-beautify/blob/master/README.md)
js:
'indent_size': 2
'indent_with_tabs': false
# More Options (https://github.com/beautify-web/js-beautify/blob/master/README.md)
sitemap:
path: sitemap.xml
imagemin:
enable : true
interlaced : false
multipass : false
optimizationLevel: 2
pngquant : false
progressive: false
theme: $THEME
deploy:
type: git
repo: $GITREPO\n" > _config.yml
npm install
}
function install_hueman_theme {
cd $SITES/$SITENAME
# theme options
get_pages_to_install
git clone https://github.com/ppoffice/hexo-theme-hueman.git themes/hueman
cd themes/hueman
printf '%s'"
# Menus
menu:
Home: /
About: About/
Projects: Projects/
Contact: Contact/
# Customize
customize:
logo:
width: 165
height: 60
url: images/logo-header.png
theme_color: '#3b8dbd'
highlight: androidstudio
sidebar: left # sidebar position, options: left, right
thumbnail: true # enable posts thumbnail, options: true, false
favicon: # path to favicon
social_links: # for more icons, please see http://fontawesome.io/icons/#brand
twitter: /
facebook: /
google-plus: /
github: $GITREPO
weibo: /
rss: /
# Widgets
widgets:
- recent_posts
- category
- archive
- tag
- tagcloud
- links
# Search
search:
swiftype: # enter swiftype install key here
baidu: false # you need to disable other search engines to use Baidu search, options: true, false
# Comment
comment:
disqus: hexo-theme-hueman # enter disqus shortname here
duoshuo: # enter duoshuo shortname here
youyan: # enter youyan uid here
# Share
share: default # options: jiathis, bdshare, addtoany, default
# Plugins
plugins:
fancybox: true # options: true, false
scrollLoading: true # options: true, false
google_analytics: # enter the tracking ID for your Google Analytics
baidu_analytics: # enter Baidu Analytics hash key
# Miscellaneous
miscellaneous:
open_graph: # see http://ogp.me
fb_app_id:
fb_admins:
twitter_id:
google_plus:
links:
Hexo: http://hexo.io" > _config.yml
npm install
}
function install_plugins {
# Plugins
echo "${GREEN}INFO${C} npm install hexo-deployer${C}"
npm install hexo-deployer-git --save
echo "${GREEN}INFO${C} npm install browsersync${C}"
# Browser Sync
npm install hexo-browsersync --save
echo "${GREEN}INFO${C} npm install hexo-beautify${C}"
# Beautify HTML/CSS/JS
npm install hexo-beautify --save
echo "${GREEN}INFO${C} npm install hexo-generator-seo-friendly-sitemap${C}"
# Sitemap
npm install hexo-generator-seo-friendly-sitemap --save
# Imagemin npm install hexo-imagemin --save
}
function generate_site {
cd $SITES/$SITENAME
clear
read -p "New Site Folder: " SITENAME
# npm install -g hexo
echo "${GREEN}INFO${C} Initializing Hexo project folder named $SITENAME.${C}"
hexo init $SITENAME && cd $_
# echo "${GREEN}INFO${C} Cleaning with npm cache clean${C}"
# npm cache clean
install_plugins
echo "${GREEN}INFO${C} Installing with npm install${C}"
npm install
clear
echo 'Choose Theme to Install'
options=("Default" "Hueman")
select opt in "${options[@]}"
do
case $opt in
"Default")
THEME='landscape'
cd $SITES/$SITENAME
npm install hexo --save
setup_parent_config
install_default_hexo_theme
cd $SITES/$SITENAME
break
;;
"Hueman")
THEME='hueman'
cd $SITES/$SITENAME
setup_parent_config
install_hueman_theme
break
;;
*) echo "INVALID";;
esac
done
npm install
hexo clean
hexo generate
read -p "Deploy to $GITREPO? [yn]: " ans
if [[ $ans = y ]] ; then
hexo deploy
fi
read -p "Open Sublime? [yn]: " ans
if [[ $ans = y ]] ; then
cd $SITES/$SITENAME
subl .
fi
read -p "Start Local Server [yn]: " ans
if [[ $ans = y ]] ; then
cd $SITES/$SITENAME
open "http://0.0.0.0:4000"
hexo server
fi
clear
echo "\n\n${YELLOW}\tSITE INFO${C}\t- Posts."
hexo list post
echo "\n\n${YELLOW}\tSITE INFO${C}\t- Pages."
hexo list page
echo "\n\n${YELLOW}\tSITE INFO$C}\t- Tags."
hexo list tag
echo "\n\n${YELLOW}\tSITE INFO${C}\t- All Routes."
hexo list route
clear
echo "\n\n${YELLOW}\tSITE INFO${C}\t - General"
echo "${GREEN}Theme${C}: $THEME"
echo "${GREEN}Repo URL${C}: $GITREPO"
echo "${GREEN}Site URL${C}: https://$GITUSERNAME.github.io/"
open "https://mavieth.github.io/"
}
function main_menu {
echo 'Please enter your choice:'
options=( "Install Fresh Website" "Push an existing website to github" "Exit" )
select opt in "${options[@]}"
do
case $opt in
"Install Fresh Website")
check_hexo_install
generate_site
break;
;;
"Push an existing website to github")
echo "Not functioning yet."
break
;;
"Exit")
break
;;
*) echo invalid option;;
esac
done
}
clear
main_menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment