Niu-X2-Sidebar is a responsive theme for pelican, built with bootstrap3.
As I am pretty new to bootstrap and jinja2, the codes look messy and may be buggy. If you find any bugs, please let me know.
BSD 3-Clause License. Please see LICENSE.txt for more details.
You can check my old blog archive for a live demo.
- Responsive.
- Disqus, duoshuo, google analytics and google custom search support.
- Pagination bar with customizable length.
- Tagcloud implemented with tagcloud.js which supports incremental search.
- Collapsible monthly archives.
- Auto-generated copyright year range, which is actually from the year of your first article to the lastest.
- Fixed position navigation bar.
- TOC(table of contents) in sidebar with the help of extract_headings plugin, with no addtional dependencies and no
[TOC]in your markdown file. - Article/Page comment on/off controled by file metadata.
- Pygments theme support.
- Categories shown in a dropdown list.
- Category aliases, which should be useful when you set
USE_FOLDER_AS_CATEGORYtoTrue. - Custom dropdown menu, footer links and footer icons through pelican configuration with custom icons.
- Translations through pelican configuration.
- Lazy load images with the jquery.lazy.load plugin. (You have to manually set
NIUX2_LAZY_LOADas True) - A toolbar.
- Support for hermit audio player.
If you are hosting your pelican site locally, please remeber to set the SITEURL variable empty in your pelican configuration, otherwise the theme will not be able to find the css and js static files correctly.
For more theme related configurations, please refer to Theme settings section below.
First clone the repository:
git clone https://github.com/mawenbao/niu-x2-sidebar
Then set THEME variable to the path of the repository folder you have just cloned in your pelican configuration.
THEME = ~/repo/niu-x2-sidebar
The theme depends on the jinja2 expression statement extension which should be added to your pelican configuration as below:
JINJA_EXTENSIONS = ['jinja2.ext.ExprStmtExtension',]
- Better responsive support.
Currently the following pelican configuration variables are supported:
DISQUS_SITENAMEis your disqus site ID.GOOGLE_ANALYTICSis your Google analytics ID.
Currently this theme supports keywords meta tag and description meta tag. The content of keywords meta tag is set as the value of Tags metadata. And the content of description meta tag is set as the value of Desc metadata.
Note that:
- All the following theme configuration variables are optional.
- All the icons are selected from iconmoon(most of them are from font-awesome). You can select your own icons from here and replace the default icons at
static/font-icons.
NIUX2_HOME_NAME, defalut SITENAME.
The theme enables comments for all the articles and pages by default. However you can disable comments for some particular articles or pages by setting Comment metadata to any value other than on, e.g.:
Title: An Article With No Comments
Date: 2013-09-09 21:38:00
Comment: off
The following configuration will hide the sidebar TOC.
Title: An Article With No TOC
Date: 2013-09-09 21:38:00
TOC: closed
And the following configuration will make TOC fixed, which is the default behaviour when TOC is not configured:
Title: An Article With fixed TOC
Date: 2013-09-09 21:38:00
TOC: fixed
Any values other than 'closed' and 'fixed' will make TOC's position static.
niu2.js is the main script used in this theme. By default the theme uses the minified version niu2.min.js which can be generated by the given Makefile. If you want to use niu2.js instead of niu2.min.js, just set NIUX2_DEBUG as True in your pelican configuration file.
This function requires the pelican-update-date plugin.
You should add the following setting to your pelican configuration.
TEMPLATE_PAGES = {
"archives_updatedate.html": "archives_updatedate.html",
}
Neighbors is needed.
Using *_article_in_category by default.
This function requires the niux2_lazyload_helper plugin.
Lazy load images(with the class name lazy) in the main content area with the lazyload jquery plugin.
NIUX2_LAZY_LOAD, default(False): enable lazy load function.NIUX2_LAZY_LOAD_TEXT, default('Loading'): the hover text upon images when loading.NIUX2_LAZY_LOAD_ICON, default('icon-spin icon-spinner'): class of the icon upon images when loading.
This function requires the niux2_hermit_player plugin.
NIUX2_404_TITLE_TRANSLstring(default "ERROR 404 Page Not Found!"), title of the 404 pageNIUX2_404_INFO_TRANSLstring(default "The requested url was not found!"), warning infomation on the 404 page
You should add the following setting to your pelican configuration.
TEMPLATE_PAGES = {
"404.html": "404.html",
}
The toolbar only supports for github/bitbucket project now.
NIUX2_TOOLBARbool(default False), enable/disable toolbar.NIUX2_GITHUB_REPOstring(default ''), repository of your github project, for examplemawenbao/niu-x2-sidebar.NIUX2_BITBUCKET_REPOstring(default ''), repository of your bitbucket project, for examplemawenbao/niu-x2-sidebar. Note that this setting will be ignored ifNIUX2_GITHUB_REPOhas been set.
First make sure you have enabled the codehilite markdown extension(pelican enables it by default). Then you can pick you favorite theme
in the static/css/pygments folder. Currently all the theme css files come from the pygments-css repository. At last you should set the NIUX2_PYGMENTS_THEME variable to the file name of the theme with no .css extension at the end. For example:
NIUX2_PYGMENTS_THEME = 'borland'
If NIUX2_PYGMENTS_THEME is not set, niu-x2-sidebar uses github theme by default.
NIUX2_GOOGLE_CSE_IDis your your google custom search engine id.NIUX2_SEARCH_TRANSLis the search text displayed in header bar, which is "Search" by default.NIUX2_SEARCH_PLACEHOLDER_TRANSLis the placeholder of your search box, which is "Press enter to search ..." by default.
The css codes above will set the width of your search box to 200px.
Currently, there is not a search result page in this theme, so I suggest that you display the search results in a Google-hosted page.
NIUX2_CATEGORY_MAP is a dictionary of category aliases, of which each item follows the format original name: (display name, icon class), if you do not want a icon, just leave the icon class empty. e.g.:
NIUX2_CATEGORY_MAP = {
"code": ("代码", "icon-code")
"note": ("笔记", ""),
}
NIUX2_HEADER_SECTIONS is a list of links displayed on the fixed position navigation bar. Each link element is a tuple with the format (link value, link title, link href, icon class) e.g.:
NIUX2_HEADER_SECTIONS = [
("关于", "about", "/about.html", "icon-anchor"),
("存档", "archives", "/archives.html", "icon-archive"),
("标签", "tags", "/tag/", "icon-tag"),
]
NIUX2_HEADER_DROPDOWN_SECTIONS is a dictionary of dropdown menu. The key is a tuple with the format (display name, icon class), and the corresponding value is actually a NIUX2_HEADER_SECTIONS list, e.g.:
NIUX2_HEADER_DROPDOWN_SECTIONS = [
("custom drop down", "icon-archive"): [
("关于", "about", "/about.html", "icon-anchor"),
("存档", "archives", "/archives.html", "icon-archive"),
],
("custom drop down2", "icon-folder-open"): [
("标签", "tags", "/tag/", "icon-tag"),
],
]
Example configuraton:
# sizes => href
NIUX2_APPLE_ICON_MAP = {
'': '/apple-touch-icon-57x57.png'
'76x76': '/apple-touch-icon-76x76.png',
'120x120': '/apple-touch-icon-120x120.png',
'152x152': '/apple-touch-icon-152x152.png',
}
NIUX2_APPLE_PRECOMPOSED_ICON_MAP = {
'': '/apple-touch-icon-precomposed-57x57.png'
'76x76': '/apple-touch-icon-precomposed-76x76.png',
'120x120': '/apple-touch-icon-precomposed-120x120.png',
'152x152': '/apple-touch-icon-precomposed-152x152.png',
}
EXTRA_PATH_METADATA = {
'extra/apple-touch-icon-76x76.png': { 'path': 'apple-touch-icon-76x76.png' },
'extra/apple-touch-icon-120x120.png': { 'path': 'apple-touch-icon-120x120.png' },
'extra/apple-touch-icon-152x152.png': { 'path': 'apple-touch-icon-152x152.png' },
}
And then drop your apple touch icons into the content/extra directory.
NIUX2_FOOTER_ICONS is a list of icon links shown in the footer section. Each element follows the format (icon class, link title, link href), e.g.:
NIUX2_FOOTER_ICONS = [
("icon-envelope-alt", "my email address", "mailto: wilbur.ma@foxmail.com"),
("icon-github-alt", "my github page", "http://github.com/wilbur-ma"),
("icon-rss", "subscribe my blog via rss", "http://atime.me/feed.xml"),
]
NIUX2_404_TITLE_TRANSLstring(default "ERROR 404 Page Not Found!"), title of the 404 pageNIUX2_404_INFO_TRANSLstring(default "The requested url was not found!"), warning infomation on the 404 pageNIUX2_TAG_TRANSLstring(default "Tag"), translation of tagNIUX2_ARCHIVE_TRANSLstring(default "Archives"), translation of archivesNIUX2_ARCHIVE_UPDATEDATE_TRANSLstring(default "Archives(by updatedate)"), translation of archives by update dateNIUX2_CATEGORY_TRANSLstring(default "Category"), translation of categoryNIUX2_TAG_CLEAR_TRANSLstring(default "clear"), name of clear button on the tags pageNIUX2_TAG_FILTER_TRANSLstring(default "filter tags"), placeholder of the tag_filter input on the tags pageNIUX2_HEADER_TOC_TRANSLstring(default "TOC"), name of the categories dropdown menuNIUX2_SEARCH_TRANSLstring(default "Search"), name displayed for google cse in the header barNIUX2_SEARCH_PLACEHOLDER_TRANSLstring(default "Press enter to search ..."), placeholder of the header search boxNIUX2_COMMENTS_TRANSLstring(default "Comments"), translation of commentsNIUX2_PUBLISHED_TRANSLstring(default "Published"), translation of publish dateNIUX2_LASTMOD_TRANSLstring(default "Last modified"), translation of last modified label, need pelican update_date plugin supportNIUX2_RECENT_UPDATE_TRANSLstring(default "Recent Updated Posts"), translation of recent updated postsNIUX2_HIDE_SIDEBAR_TRANSLstring(default "Hide Sidebar")NIUX2_SHOW_SIDEBAR_TRANSLstring(default "Show Sidebar")NIUX2_REVISION_HISTORY_TRANSLstring(default "Revision History")NIUX2_VIEW_SOURCE_TRANSLstring(default "View Source")NIUX2_AUTHOR_TRANSLstring(default "Author")
NIUX2_BAIDU_TJstring(default ""), baidu tongji id.NIUX2_TOOLBAR_LOAD_ICONstring(default "icon-spin icon-4x icon-spinner"), the class of the rotating icon which shows on top the whole page when we hide/show sidebar toc.NIUX2_PAGINATOR_LENGTHint(default 11), the length of your pagination barNIUX2_FAVICON_URLstring(default "/favicon.png"), your favicon urlNIUX2_FOOTER_LINKSaNIUX2_HEADER_SECTIONSformat list shown right after your copyright info in the footer sectionNIUX2_DISPLAY_TITLEboolean(default True), whether to display the title of article and pageNIUX2_DUOSHUO_SHORTNAMEstring(default None), your duoshuo shortname. Note that ifDISQUS_SITENAMEis set, duoshuo will not be loaded.NIUX2_DUOSHUO_THREAD_KEYstring(default ""), type of your duoshuo thread key. If you want to use article's slug for its thread key, change it to 'slug' or 'date' for using article's date. Otherwise, it will use part of the article's url as its thread key by default.NIUX2_LIB_THEMEstring(default SITEURL+'/theme'), url of niu-x2-sidebar theme rootNIUX2_LIB_FONT_ICONSstring(default SITEURL+'/theme/font-icons'), url of your custom font icons.NIUX2_LIB_FONTAWESOMEstring(default ''), url of font awesome icons.NIUX2_LIB_BOOTSTRAPstring(default SITEURL+'/theme'), url of bootstrap libraryNIUX2_LIB_JQUERYstring(default SITEURL+'/theme/js/jquery-1.10.2.min.js'), url of jqueryNIUX2_LAZY_LOADbool(default False), enable lazy loading images.NIUX2_DEBUGbool(default False), if set as True, use niu2.js instead of niu2.min.jsNIUX2_AUTHOR_LINKstring(default 'SITEURL'), the author link of ariticlesNIUX2_RECENT_UPDATE_NUMint(default 10), number of your recent updated posts in the sidebar, require pelican-update-date plugin
