Skip to content

Commit

Permalink
Patch for v0.2.2 (#12)
Browse files Browse the repository at this point in the history
* Add some meta tag

* Improve style of code block

* Implement `bannerOf` helper, and use for thumbnail

* Insert banner image in article content

close #4
  • Loading branch information
HyunSeob authored Oct 2, 2016
1 parent 7bc11b4 commit dede7a5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion _config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ profile:
description:
social:
github:
facebook:
facebook: # Facebook property also used in `article:author` meta tag.
linkedin:
instagram:
twitter:
Expand Down
11 changes: 1 addition & 10 deletions layout/includes/article.jade
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ article#article.article(itemscope itemtype="https://schema.org/BlogPosting")
)= category.name
unless index === page.categories.length - 1
span.article__meta__categories__separator >
if page.banner && page.banner.url
img.article__image(
src=page.banner.url
alt="Post Image")
else if page.photos && page.photos.length
each photo in page.photos
img.article__image(
src=photo
alt="Gallery Image")
else
unless (page.banner && page.banner.url) || (page.photos && page.photos.length)
hr

.article__contents
Expand Down
5 changes: 4 additions & 1 deletion layout/includes/head.jade
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- if (is_month()) pageTitle += ': ' + page.month + '/' + page.year;
- if (is_year()) pageTitle += ': ' + page.year;
- pageTitle = pageTitle ? pageTitle += ' | ' + config.title : config.title;
- var banner = page.banner ? page.banner.url : (page.photos ? page.photos[0] : theme.default.url);
- var banner = bannerOf(page) || theme.default.url;
-
var openGraph = open_graph({
description: page.content || config.description || theme.profile.description,
Expand All @@ -17,6 +17,7 @@
});
meta(charset='UTF-8')
meta(http-equiv="X-UA-Compatible" content="IE=edge")
meta(name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1")

title= pageTitle
Expand All @@ -37,6 +38,8 @@ link(rel="stylesheet" href="/css/index.css")

| !{ canonical(config, page) }
| !{ openGraph }
if is_post()
meta(property="article:author" content=theme.profile.social.facebook || config.author)

if theme.favicon
link(rel="icon" href=theme.favicon)
Expand Down
2 changes: 1 addition & 1 deletion layout/includes/post-list.jade
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ section.post-list
article.post-list__item
.post-list__item__col-1
a.post-list__item__link(href=url_for(post.path))
- var banner = post.banner ? post.banner.url : (post.photos[0] || theme.default.url)
- var banner = bannerOf(post) || theme.default.url;
.post-list__item__link__background(style="background-image: url('#{ banner }')")
.post-list__item__col-2
.post-list__item__meta
Expand Down
2 changes: 1 addition & 1 deletion layout/post.jade
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ block content
each post in relatedPosts
.related-posts__item__wrapper
a.related-posts__item(href=url_for(post.path))
- var banner = post.banner ? post.banner.url : ((post.photos && post.photos.length) ? post.photos[0] : theme.default.url);
- var banner = bannerOf(post) || theme.default.url;
.related-posts__item__background(style="background-image: url('#{ banner }')")
.related-posts__item__overlay
span.related-posts__item__title= post.title || 'Untitled'
18 changes: 18 additions & 0 deletions scripts/banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Banner Helper
* @description Get banner url from post.
* @example
* bannerOf(post);
*/

hexo.extend.helper.register('bannerOf', function (post) {
var url = post.banner ? post.banner.url : (post.photos && post.photos.length ? post.photos[0] : '');
var imgRegex = /\<img\s.*?\s?src\s*=\s*['|"]?([^\s'"]+).*?\>/ig;
if (!url) {
var result = imgRegex.exec(post.content);
if (result && result.length > 1) {
url = result[1];
}
}
return url;
});
18 changes: 18 additions & 0 deletions scripts/before_post_render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Filter triggered by post rendering.
*/

function imgTpl(url) {
return '<img src="' + url + '"/>';
}

hexo.extend.filter.register('before_post_render', function (data) {
if (data.banner) {
var img = imgTpl(data.banner.url);
data.content = img + data.content;
} else if (data.photos && data.photos.length) {
var imgs = data.photos.map(imgTpl).join('');
data.content += imgs + data.content;
}
return data;
});
21 changes: 16 additions & 5 deletions source/css/code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@
}
.keyword,
.selector-tag,
.literal,
.section,
.link {
color: #8be9fd;
color: #ff79c6;
}
.literal,
.number {
color: #bd93f9;
}
.function .keyword {
color: #ff79c6;
color: #8be9fd;
}
.title {
color: #50fa7b;
}
.params {
color: #ffb86c;
}
.string,
.title,
.name,
.type,
.attribute,
Expand Down Expand Up @@ -51,7 +59,10 @@
.strong {
font-weight: bold;
}
.emphasis {
.emphasis, .built_in {
font-style: italic;
}
.built_in {
color: #8be9fd;
}
}

0 comments on commit dede7a5

Please sign in to comment.