This documentation will help you to understand Tranquilpeak Hexo theme code.
If you want to report a bug or ask a question, create an issue.
Summary
General
- Author : Louis Barranqueiro
- Version : 1.10.0
- Compatibility : Node v4 or later, Hexo v3.0.0 or later
Requirements
- Node : v4 or higher. Download Node
- Hexo CLI : v0.1.4 or higher. Run
npm install hexo-cli -g
- Grunt CLI : v0.1.13 or higher. Run
npm install grunt-cli -g
- Bower : v1.4.1 or higher. Run
npm install bower -g
Installation
- Run
git clone https://github.com/LouisBarranqueiro/hexo-theme-tranquilpeak.git
- Rename the folder in
tranquilpeak
and place it inthemes
folder of your Hexo blog - Modify the theme in
_config.yml
by changingtheme
variable totranquilpeak
- Complete
theme/tranquilpeak/_config.yml
with your information by following directives in comments - Go in
theme/tranquilpeak
folder withcd themes/tranquilpeak
- Install requirements
- Run
npm install
to install NPM dependencies - Run
bower install
to install Bower dependencies
If you want to configure the theme, please follow the user documentation
Code style
We use ESLint based on Google code style to maintain javascript code style.
Check code style with :
npm run lint
# or
grunt eslint
Code structure
tranquilpeak
├── .github
├── docs
├── languages
├── layout
├── scripts
├── source
└── tasks
File/Folder | Description |
---|---|
.github | Contains file templates for GitHub |
docs | Contains user and developer documentation |
languages | Contains language files |
layout | Contains all views |
scripts | Contains all scripts executed at the startup of Hexo |
source | Contains all assets (css, js and images) |
tasks | Contains all grunt tasks |
Languages
Each file contains all the labels used in the theme.
If you want to add a new language, duplicate an existing language file and replace every string with their translation.
Views
├── layout
├── _partial
│ ├── post
│ ...
...
...
Folder | Description |
---|---|
layout | Contails all mains views |
layout/partial | Contains all partial views included in main views |
layout/partial/post | Contains all partial views to build post |
Scripts
├── scripts
├── filters
├── helpers
├── migrators
└── tags
Each script is executed at the startup of Hexo. They are separated by categories:
Folder | Description |
---|---|
filters | A filter is used to modify some specified data. Hexo passes data to filter in sequence and filters can modify the data. |
helpers | Helpers are used in templates to help insert snippets quickly. Helpers cannot be used in source files. |
migrators | A migrator helps users migrate posts from other system or Hexo theme to Hexo. |
tags | A tag helps users insert snippets to posts easily. |
Assets
Stylesheets
SCSS structure follow 7-1 pattern of sass guidelines
If you want more information to better understand this code, consult sass guidelines
Fonts
├── _fonts
└── .gitkeep
File | Description |
---|---|
.gitkeep | Ignore this file. It only exists because git refuses to push empty directories to a remote server. .gitkeep is an unofficial convention that has emerged as a workaround for people who don’t discriminate against empty directories. |
If you have local fonts, place them in this folder and import them in source/_css/utils/_fonts.scss
.
Images
├── _images
└── cover.jpg
File | Description |
---|---|
cover.png | Default background cover of the blog |
Contains all images of the theme.
Javascript
├── _js
├── .eslintrc.json
├── about.js
├── archives-filter.js
├── categories-filter.js
├── codeblock-resizer.js
├── fancybox.js
├── header.js
├── image-gallery.js
├── post-bottom-bar.js
├── share-options.js
├── sidebar.js
├── smartresize.js
├── tabbed-codeblocks.js
└── tags-filter.js
File | Description |
---|---|
about.js | Fade out the blog and let drop the about card of the author and vice versa |
archives-filter.js | Filter posts by using their date on archives page : /archives |
categories-filter.js | Filter posts by using their categories on archives page : /categories |
codeblock-resizer.js | Resize code blocks to fit the screen width |
fancybox.js.js | Run Fancybox plugin |
header.js | Hide the header when the user scrolls down, and show it when he scrolls up |
image-gallery.js | Resize all images of an image-gallery |
post-bottom-bar.js | Hide the post bottom bar when the post footer is visible by the user, and vice versa |
share-options.js | Open and close the share-options bar |
sidebar.js | Open and close the sidebar by swiping the sidebar and the blog and vice versa |
smartresize.js | Debouncing function from John Hann |
tabbed-codeblocks.js | Animate tabs of tabbed code blocks |
tags-filter.js | Filter posts by using their tags on archives page : /tags |
Each file correspond to a feature.
NPM scripts
Use npm run <script_name>
to run one of these scripts. E.g : npm run start
npm run ... | Description |
---|---|
start | Build the theme once and rebuild after each change |
prod | Build the theme for production. (synchronize bower dependencies, images, fonts, compile assets (css and js) with some optimization (concat and minify) and link it to views) |
lint | Check code style with ESLint |
Grunt tasks
Tasks structure
├── tasks
├── config
├── register
└── pipeline.js
File/folder | Description |
---|---|
config | Default tasks |
register | Alias tasks which call multiple default tasks |
pipeline.js | Files which contains a list of javascript and stylesheets files linked to the blog |
Pipeline
// Js files to inject in `layout/_partial/script.ejs`
var tranquilpeakJsFilesToInject = [
'jquery.js',
'jquery.fancybox.js',
'jquery.fancybox-thumbs.js',
'tranquilpeak.js'
];
// Css files to inject in `layout/_partial/head.ejs`
var tranquilpeakCssFilesToInject = [
'font-awesome.css',
'jquery.fancybox.css',
'jquery.fancybox-thumbs.css',
'tranquilpeak.css'
];
Variable | Description |
---|---|
tranquilpeakJsFilesToInject | Files injected in layout/_partial/script.ejs (developement environment) |
tranquilpeakCssFilesToInject | Files injected inlayout/_partial/head.ejs (developement environment) |
In the production environment, these javascript and stylesheets files are concatenated and minified into 1 javascript file and 1 stylesheet file and linked to their respective views.
Config tasks
Task | Description |
---|---|
bower | Copy all needed files by types from bower dependencies |
clean | Delete source/assets folder |
concat |
|
cssmin | Minify source/assets/cssstyle.css file in : source/assets/cssstyle.min.css |
exec |
|
replace |
|
sails-linker |
|
sass | Compile source/_css/tranquilpeak.scss file in source/assets/css/tranquilpeak.css |
sync | Synchronize images from source/_images to source/assets/images and fonts from source/_fonts to source/assets/fonts |
watch | Watch assets from source/_*/**/* folder to detect changes and launch syncAssets task |
Register tasks
Task | Description |
---|---|
build | Synchronize bower dependencies, images, fonts, compile assets (css and js) and link it to views |
buildProd | Synchronize bower dependencies, images, fonts, compile assets (css and js) with some optimization (concat and minify) and link it to views |
default | Build the theme once and rebuild after each change |
eslint | Check code style with ESLint |
compileAssets | Compile scss files and concat js files |
linkAssets | Link all javascript and stylesheets files to views |
linkAssetsProd | Link one javascript file and one stylesheet file (concatenated and minified) to views |
syncAssets | Synchronize assets (css, js, fonts and images) |
When you run grunt build
or grunt buildProd
tasks, a source/assets
folder will be created with all files generated in. When you will start your hexo server, only this folder will be copied in public
folder
Build
Development environment
- Run
npm run start
orgrunt default
and start coding :)
Production environment (before deploying your blog)
- Run
npm run prod
orgrunt buildProd
to build the project with some optimization (concat and minify) to reduce number of HTTP requests and improve performance.
Running
Run hexo server
and start coding! :)