Skip to content

Commit

Permalink
Add "News" section. Modify the style of header.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jun 13, 2014
1 parent b1d71b5 commit b058118
Show file tree
Hide file tree
Showing 30 changed files with 365 additions and 128 deletions.
76 changes: 50 additions & 26 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
# Basic
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/tommy351/hexo/

# Site
title: Hexo
subtitle: Hexo is a fast, simple & powerful blog framework powered by Node.js.
description: Hexo is a fast, simple & powerful blog framework powered by Node.js.
url: http://hexo.io
author: SkyArrow
email: [email protected]
language:

# Permalink
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://hexo.io
root: /
permalink: :category/:title/
permalink: news/:year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: posts
archive_dir: news
category_dir: categories
code_dir: downloads/code

# Directory
source_dir: source
public_dir: public

# Writing
new_post_name: :year-:month-:day-:title.md # File name of new posts
default_layout: post
auto_spacing: false # Add spaces between asian characters and western characters
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
max_open_file: 100
multi_thread: true
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
highlight:
enable: true
line_number: false
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Archives
# 2: Paginate result
Expand All @@ -22,46 +54,38 @@ category: 2
tag: 2

# Server
# Hexo uses Connect to serve static files
# Reference: http://www.senchalabs.org/connect/
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
server_ip: 0.0.0.0
logger: false
logger_format:

# Date / Time format
# Hexo uses Moment.js to parse and display date
# Reference: http://momentjs.com/docs/#/displaying/format/
date_format: MMM D, YYYY
## 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: MMM D YYYY
time_format: H:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 0
pagination_dir: page

# Disqus
disqus_shortname: hexojs

# Extensions
plugins:
## Plugins: https://github.com/tommy351/hexo/wiki/Plugins
## Themes: https://github.com/tommy351/hexo/wiki/Themes
theme: hexo3
exclude_generator:
- category
- tag
- home
- post
- archive

# Enhancement
auto_spacing: false
titlecase: false
highlight:
enable: true
line_number: false
tab_replace: ' '

# Deployment
# Type: github, heroku
# Read documentaion for more information
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: github
repo: https://github.com/hexojs/hexojs.github.io.git
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"hexo-renderer-stylus": "^0.1.0",
"hexo-renderer-jade": "^0.1.0",
"hexo-yuidoc": "^0.1.0",
"hexo-generator-sitemap": "^0.1.2"
"hexo-generator-sitemap": "^0.1.2",
"hexo-generator-feed": "^0.1.1"
},
"devDependencies": {
"gulp": "^3.6.2",
Expand All @@ -17,4 +18,4 @@
"gulp-shell": "^0.2.4",
"gulp-rename": "^1.2.0"
}
}
}
66 changes: 66 additions & 0 deletions source/_posts/2014-06-14-hexo-2-7-released.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
title: Hexo 2.7 Released
---
Hexo 2.7 has been released with three new features. I'm going to introduce them below.

## Fragment Caching

Although Hexo is fast, it may become slow if you have thousands of source files or complicated categories or tags. Before the data model upgraded, I borrowed a feature from Ruby on Rails: **Fragment Caching**.

Fragment Caching saves contents within a fragment and serves the cache when the next request come in. A fragment will only be processed once. It can reduce database queries and decrease generation time significantly. For instance, a Hexo site with 300+ source files needs 6 minutes to generate. In Hexo 2.7, it only need 10 seconds!

It can be used in header, footer, sidebar or static contents that won't be changed during generating. For example:

``` js
<%- fragment_cache('header', function(){
return '<header></header>';
});
```

By using `fragment_cache` helper, contents in the function will be cached.

Partial helper also supports Fragment Caching, you only need to add a `{cache: true}` option when using partial.

``` js
<%- partial('header', {}, {cache: true}) %>
```

[Landscape] is updated and supports Fragment Caching now. You can check [this commit](https://github.com/hexojs/hexo-theme-landscape/commit/d2aedda61571d6994eb72d784ceda2f59d2a8631) to see what's changed.

## Relative Link

Relative Link is supported since Hexo 2.7. But your theme needs some modifications to support it. However, it's not as hard as you think. You just need to replace the following contents in templates

``` js
<%- config.root %><%- path %>
```

with `url_for` helper.

``` js
<%- url_for(path) %>
```

`url_for` helper will add `config.root` automatically for you. If you enable `relative_link` setting, it'll add a relative path.

[Landscape] is updated for Relative Link. You can check [this commit](https://github.com/hexojs/hexo-theme-landscape/commit/d29cbb83356373af27e7b98643f29a27804364af) to see what's changed.

## Server Middleware

Server Middleware would be familiar if you have ever used [Connect] or [Express] before. [Connect] passes a request through functions called **middleware**. You can make response to the coming in request in middleware.

In Hexo, middleware is served as a type of filter. You can add middleware by registering a new filter. For example:

``` js
hexo.extend.filter.register('server_middleware', function(app){
app.use(function(req, res, next){
res.setHeader('X-Powered-By', 'Hexo');
next();
});
});
```

This middleware add a header `X-Powered-By` and passes the request to the next middleware.

[Landscape]: https://github.com/hexojs/hexo-theme-landscape
[Connect]: http://www.senchalabs.org/connect/
[Express]: http://expressjs.com/
4 changes: 2 additions & 2 deletions source/docs/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ For more info, see [partial helper](helpers.html#partial).

If your theme is too complicated and too may source files needed to be generate. Generation performance may decrease a lot. Besides simplifying your theme, you can also try **Fragment Caching** introduced in Hexo 2.7.

This feature is stolen from [Ruby on Rails](http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching). It saves the contents within a fragment and serves the cache when the next request comes in. It can decrease database queries and make generation faster.
This feature is stolen from [Ruby on Rails](http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching). It saves the contents within a fragment and serves the cache when the next request comes in. It can reduce database queries and make generation faster.

It can be used in header, footer, sidebar or some static contents that won't be changed in your templates. For example:
It can be used in header, footer, sidebar or static contents that won't be changed in your templates. For example:

``` js
<%- fragment_cache('header', function(){
Expand Down
5 changes: 3 additions & 2 deletions themes/hexo3/_config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
menu:
Docs: /docs/
API: /api/classes/Hexo.html
News: /news/
Plugins: https://github.com/tommy351/hexo/wiki/Plugins
Themes: https://github.com/tommy351/hexo/wiki/Themes
Source: https://github.com/tommy351/hexo

doc_sidebar:
Getting Started:
Expand Down Expand Up @@ -35,4 +35,5 @@ doc_sidebar:
google_analytics: UA-4910098-10
fb_admins: 100000247608790
swiftype_key: DDvzs7LQ9kdKssQNQLcv
twitter: hexojs
twitter: hexojs
github: tommy351/hexo
24 changes: 13 additions & 11 deletions themes/hexo3/layout/_partial/after-footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
<!-- Swiftype -->
<script>
var Swiftype = window.Swiftype || {};
(function() {
Swiftype.key = '<%- theme.swiftype_key %>';
(function() {
Swiftype.key = '<%- theme.swiftype_key %>';
/** DO NOT EDIT BELOW THIS LINE **/
var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
script.src = "//s.swiftypecdn.com/embed.js";
var entry = document.getElementsByTagName('script')[0];
document.getElementsByTagName('script')[0].parentNode.insertBefore(script, entry);
}());
/** DO NOT EDIT BELOW THIS LINE **/
var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
script.src = "//s.swiftypecdn.com/embed.js";
var entry = document.getElementsByTagName('script')[0];
document.getElementsByTagName('script')[0].parentNode.insertBefore(script, entry);
}());
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="<%- config.root %>js/script.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<%- js('js/script') %>
<!-- Google+ -->
<script type="text/javascript" src="//apis.google.com/js/plusone.js"></script>
<!-- Twitter -->
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
14 changes: 14 additions & 0 deletions themes/hexo3/layout/_partial/article.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<article class="post<% if (full){ %> full<% } %>" itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<%- partial('post/title') %>
<%- partial('post/date') %>
</header>
<% if (full){ %>
<div class="page-entry" itemprop="articleBody">
<%- post.content %>
</div>
<% } %>
<% if (!index){ %>
<%- partial('comment') %>
<% } %>
</article>
7 changes: 7 additions & 0 deletions themes/hexo3/layout/_partial/comment.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if (page.comments && config.disqus_shortname){ %>
<section id="comments">
<div id="disqus_thread">
<noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
<% } %>
2 changes: 1 addition & 1 deletion themes/hexo3/layout/_partial/footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<div id="footer-links">
<a href="https://twitter.com/<%= theme.twitter %>" id="footer-link-twitter" class="footer-link" target="_blank"><span>Twitter</span></a>
<a href="https://github.com/tommy351/hexo" id="footer-link-github" class="footer-link" target="_blank"><span>GitHub</span></a>
<a href="https://github.com/<%- theme.github %>" id="footer-link-github" class="footer-link" target="_blank"><span>GitHub</span></a>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion themes/hexo3/layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<title><% if (page.title){ %><%= page.title %> | <% } %>Hexo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="canonical" href="<%- page.permalink %>">
<link rel="shortcut icon" href="<%- url_for('favicon.ico') %>">
<%- favicon_tag('favicon.ico') %>
<link href="<%- url_for('apple-touch-icon.png') %>" rel="apple-touch-icon">
<link href="<%- url_for('apple-touch-icon-76x76.png') %>" rel="apple-touch-icon" sizes="76x76">
<link href="<%- url_for('apple-touch-icon-120x120.png') %>" rel="apple-touch-icon" sizes="120x120">
<link href="<%- url_for('apple-touch-icon-152x152.png') %>" rel="apple-touch-icon" sizes="152x152">
<%- css('css/style') %>
<link href="//fonts.googleapis.com/css?family=Lato:300,700" rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro:400,700" rel="stylesheet" type="text/css">
<%- feed_tag('atom.xml') %>
<%- open_graph({
fb_admins: theme.fb_admins,
twitter_site: '@' + theme.twitter,
Expand Down
3 changes: 2 additions & 1 deletion themes/hexo3/layout/_partial/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<ul id="main-nav-list">
<% _.each(theme.menu, function(menu, title){ %>
<li class="main-nav-item">
<a href="<%= url_for(menu) %>" class="main-nav-link<% if (is_current(menu)){ %> current<% } %>"><%= title %></a>
<a href="<%= url_for(menu) %>" class="main-nav-link"><%= title %></a>
</li>
<% }); %>
</ul>
<a href="https://github.com/<%- theme.github %>" id="github-btn" title="GitHub" target="_blank"></a>
<a id="search-btn" class="st-search-launcher" title="Search"></a>
</nav>
</div>
Expand Down
8 changes: 8 additions & 0 deletions themes/hexo3/layout/_partial/news-banner.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<header id="page-banner">
<div class="outer">
<div id="page-banner-inner" class="inner">
<h1 id="page-title">News</h1>
<a href="<%- url_for('atom.xml') %>" title="Subscribe for latest news" id="news-subscribe-link"></a>
</div>
</div>
</header>
5 changes: 5 additions & 0 deletions themes/hexo3/layout/_partial/post/date.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="post-date-wrap">
<a href="<%- url_for(post.path) %>" class="post-date">
<time datetime="<%= date_xml(post.date) %>" itemprop="datePublished"><%= date(post.date) %></time>
</a>
</div>
15 changes: 15 additions & 0 deletions themes/hexo3/layout/_partial/post/title.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if (post.link){ %>
<h1 itemprop="name">
<a class="post-title" href="<%- url_for(post.link) %>" target="_blank" itemprop="url"><%= post.title %></a>
</h1>
<% } else if (post.title){ %>
<% if (index){ %>
<h1 itemprop="name">
<a class="post-title" href="<%- url_for(post.path) %>"><%= post.title %></a>
</h1>
<% } else { %>
<h1 class="post-title" itemprop="name">
<%= post.title %>
</h1>
<% } %>
<% } %>
10 changes: 10 additions & 0 deletions themes/hexo3/layout/archive.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% page.title = 'News' %>
<%- partial('_partial/news-banner') %>

<div id="post-list" class="outer">
<div class="inner">
<% page.posts.each(function(post, i){ %>
<%- partial('_partial/article', {post: post, full: i === 0, index: true}) %>
<% }) %>
</div>
</div>
2 changes: 1 addition & 1 deletion themes/hexo3/layout/layout.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%- partial('_partial/head') %>

<body class="<%= page.layout || 'page' %>">
<body>
<%- partial('_partial/header') %>
<%- body %>
<%- partial('_partial/footer') %>
Expand Down
8 changes: 1 addition & 7 deletions themes/hexo3/layout/page.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
<time id="page-footer-updated" datetime="<%= date_xml(page.updated) %>" itemprop="dateModified">Last updated: <%= date(page.updated) %></time>
<%- page_nav() %>
</footer>
<% if (page.comments && config.disqus_shortname){ %>
<section id="comments">
<div id="disqus_thread">
<noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
<% } %>
<%- partial('_partial/comment') %>
</div>
<%- partial('_partial/sidebar') %>
</div>
Expand Down
Loading

0 comments on commit b058118

Please sign in to comment.