Paporubio developer documentation

The definitive guide to the javascript tooling landscape in 2017

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

  1. Node : v4 or higher. Download Node
  2. Hexo CLI : v0.1.4 or higher. Run npm install hexo-cli -g
  3. Grunt CLI : v0.1.13 or higher. Run npm install grunt-cli -g
  4. Bower : v1.4.1 or higher. Run npm install bower -g

Installation

  1. Run git clone https://github.com/LouisBarranqueiro/hexo-theme-tranquilpeak.git
  2. Rename the folder in tranquilpeak and place it in themes folder of your Hexo blog
  3. Modify the theme in _config.yml by changing theme variable to tranquilpeak
  4. Complete theme/tranquilpeak/_config.yml with your information by following directives in comments
  5. Go in theme/tranquilpeak folder with cd themes/tranquilpeak
  6. Install requirements
  7. Run npm install to install NPM dependencies
  8. 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/FolderDescription
.githubContains file templates for GitHub
docsContains user and developer documentation
languagesContains language files
layoutContains all views
scriptsContains all scripts executed at the startup of Hexo
sourceContains all assets (css, js and images)
tasksContains 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
    │   ...
    ...
...
FolderDescription
layoutContails all mains views
layout/partialContains all partial views included in main views
layout/partial/postContains 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:

FolderDescription
filtersA filter is used to modify some specified data. Hexo passes data to filter in sequence and filters can modify the data.
helpersHelpers are used in templates to help insert snippets quickly. Helpers cannot be used in source files.
migratorsA migrator helps users migrate posts from other system or Hexo theme to Hexo.
tagsA 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
FileDescription
.gitkeepIgnore 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
FileDescription
cover.pngDefault 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
FileDescription
about.jsFade out the blog and let drop the about card of the author and vice versa
archives-filter.jsFilter posts by using their date on archives page : /archives
categories-filter.jsFilter posts by using their categories on archives page : /categories
codeblock-resizer.jsResize code blocks to fit the screen width
fancybox.js.jsRun Fancybox plugin
header.jsHide the header when the user scrolls down, and show it when he scrolls up
image-gallery.jsResize all images of an image-gallery
post-bottom-bar.jsHide the post bottom bar when the post footer is visible by the user, and vice versa
share-options.jsOpen and close the share-options bar
sidebar.jsOpen and close the sidebar by swiping the sidebar and the blog and vice versa
smartresize.jsDebouncing function from John Hann
tabbed-codeblocks.jsAnimate tabs of tabbed code blocks
tags-filter.jsFilter 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
startBuild the theme once and rebuild after each change
prodBuild 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)
lintCheck code style with ESLint

Grunt tasks

Tasks structure

├── tasks
    ├── config
    ├── register
    └── pipeline.js
File/folderDescription
configDefault tasks
registerAlias tasks which call multiple default tasks
pipeline.jsFiles 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'
];
VariableDescription
tranquilpeakJsFilesToInjectFiles injected in layout/_partial/script.ejs (developement environment)
tranquilpeakCssFilesToInjectFiles 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

TaskDescription
bowerCopy all needed files by types from bower dependencies
cleanDelete source/assets folder
concat
  • devJs : Concat all javascript files located in source/_js/ into 1 file : source/assets/js/tranquilpeak.js
  • prodCss : Concat all stylesheets files located in source/assets/css/ into 1 file : source/assets/css/style.css
  • prodJs : Concat all javascript listed in tasks/pipeline.js in 1 file : source/assets/js/script.js
cssminMinify source/assets/cssstyle.css file in : source/assets/cssstyle.min.css
exec
  • eslint : run eslint .
replace
  • linker : Replace EJS_ENDTAG string to resolve a problem of ejs escaping with sails-linker tasks
  • cssFancybox : Resolve path of images in fancybox.css. Impossible to use an other plugin to do that because in the bower fancybox packages, css files and images are in the same folder and that not the case in assets folder.
  • cssTranquilpeak : Resolve path of images and fonts in tranquilpeak.css.
sails-linker
  • devJs : Link all javascript files listed in tasks/pipeline.js to layout/_partial/script.ejs
  • devCss : Link all stylesheets files listed in tasks/pipeline.js to layout/_partial/head.ejs
  • prodJs : Link source/assets/js/script.min.js file in layout/_partial/script.ejs
  • prodCss : Link source/assets/js/style.min.css file in layout/_partial/head.ejs
sassCompile source/_css/tranquilpeak.scss file in source/assets/css/tranquilpeak.css
syncSynchronize images from source/_images to source/assets/images and fonts from source/_fonts to source/assets/fonts
watchWatch assets from source/_*/**/* folder to detect changes and launch syncAssets task

Register tasks

TaskDescription
buildSynchronize bower dependencies, images, fonts, compile assets (css and js) and link it to views
buildProdSynchronize bower dependencies, images, fonts, compile assets (css and js) with some optimization (concat and minify) and link it to views
defaultBuild the theme once and rebuild after each change
eslintCheck code style with ESLint
compileAssetsCompile scss files and concat js files
linkAssetsLink all javascript and stylesheets files to views
linkAssetsProdLink one javascript file and one stylesheet file (concatenated and minified) to views
syncAssetsSynchronize 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

  1. Run npm run start or grunt default and start coding :)

Production environment (before deploying your blog)

  1. Run npm run prod or grunt 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! :)