Skip to content

Commit

Permalink
Dark mode (#106)
Browse files Browse the repository at this point in the history
* update some text

* update front-end source

* fix incorrect modification of article img
  • Loading branch information
ikeq authored Jul 10, 2019
1 parent 0c49e12 commit 0f75794
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 84 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
## Features

- SPA built with [angular]
- Custom accent color, background, fonts
- Custom accent color, background, fonts, dark mode
- Custom code syntax highlighting
- Sub-page routes
- Internationalization (i18n)
- :cn: Simplified Chinese & Traditional Chinese
- :us: English
- :jp: Japanese
- Sub-page
- Search
- Comments
- [Disqus]
Expand All @@ -47,10 +43,8 @@
- [manifest.json]
- Offline support ([workbox])
- SEO
- Canonical link
- Built-in `sitemap.xml`
- [Structured Data]
- Open Graph Meta Tags

## Quick start

Expand Down
10 changes: 2 additions & 8 deletions README_zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
## 特色

- SPA built with [angular]
- 自定义色调、背景、字体
- 自定义色调、背景、字体、暗色主题
- 自定义代码语法高亮
- 可嵌套的 page 路由
- 多语言 (i18n)
- :cn: Simplified Chinese & Traditional Chinese
- :us: English
- :jp: Japanese
- 可嵌套 page 路由
- 评论
- [Disqus]
- [LiveRe]
Expand All @@ -46,10 +42,8 @@
- [manifest.json]
- 离线支持 ([workbox])
- SEO
- canonical link
- 内置 `sitemap.xml`
- [Structured Data]
- Open Graph Meta Tags

## 开始使用

Expand Down
39 changes: 24 additions & 15 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ appearance:
# - 'url(//www.toptal.com/designers/subtlepatterns/patterns/confectionary.png) #f5f7fa'
# - '#2a2b33'

# You can also set only the background when the sidebar is open.
# background:
# - '#2a2b33'

# Maximum width of content
# content_width: 640

Expand Down Expand Up @@ -48,9 +52,9 @@ appearance:
# Code and code block
code: Inconsolata, monospace

# Code Highlight theme
# Code Syntax Highlighting
# Uses an architecture called "base16" (https://github.com/chriskempson/base16),
# the default highlight theme is a customized Atelier Dune Light theme,
# the default theme is a customized Atelier Dune Light theme,
# please feel free to explore more.
highlight:

Expand Down Expand Up @@ -78,29 +82,38 @@ appearance:
# '#8abeb7', '#81a2be', '#b294bb', '#a3685a'
# ]

# Mode
# Specify `dark` to apply a built-in dark mode,
# or fully custom colors: `[foreground color, card background, border-color]`
# Note, the middle value can be any valid css background value
# `mode: dark` is equivalent to `mode: ['#d8d8d8', '#252525', '#444']`
mode:

# Sidebar profile
profile:
# `email` will fallback to `hexo.config.email` if not specified
# `email` is used for gravatar(https://en.gravatar.com),
# fallback to `hexo.config.email` if not specified
email:

# Avatar URL, email address will be used for gravatar(https://en.gravatar.com) avatar if not specified.
# You can set Avatar URL directly
# avatar:

bio: Awesome guy.

# Sidebar menu
# Sidebar navigation links
menu:
Home: /
# About: /about
# Links: /links
# Github: https://github.com/username

# Sidebar social media
# Social media URL
# Try to sort by changing the order of the keys
sns:
# `email` will fallback to `profile.email` if not specified
email:
# `feed` will fallback to `hexo.config.feed.path` if not specified
# If you use hexo-generator-feed, `sns.feed` can be left blank
# and the theme will try to get `hexo.config.feed.path`.
feed:
github:
twitter:
Expand All @@ -118,10 +131,10 @@ sns:
weibo:
qq:

# Sidebar footer
# Sidebar footer copyright info
footer:
# Default to `©year • author`, set to false to disable.
# copyright:
# Set to false to hide.
# copyright: '&copy; 2019 • <a href="">John Doe</a>'

# Set to false to hide Hexo link.
# powered: false
Expand Down Expand Up @@ -154,13 +167,9 @@ page:
post:
# per_page: 10

# Display Table of content, default to `true`
# The following settings are the same as the page
# toc: false

# Display reward, default to `false`
# reward: true

# Display copyright notice, default to `false`
# copyright: true

# Archive
Expand Down
14 changes: 14 additions & 0 deletions lib/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
"type": "array",
"items": { "$ref": "#/definitions/color" },
"minItems": 15
},
"mode": {
"oneOf": [
{ "enum": ["dark"] },
{
"type": "array",
"items": [
{ "$ref": "#/definitions/color" },
{ "type": "string" },
{ "$ref": "#/definitions/color" }
],
"minItems": 3
}
]
}
},
"required": ["accent_color"],
Expand Down
14 changes: 6 additions & 8 deletions lib/filter/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const cheerio = require('cheerio');
const { date } = require('hexo/lib/plugins/helper/date');
const bounded = '<div class="article-bounded"></div>';
const table = '<div class="article-table"></div>';
const img = '<div class="article-img"></div>';
const { snippet, getPagePath, parseToc, isObject, isEmptyObject, localeId, pick } = require('../utils');

// cache
Expand Down Expand Up @@ -112,18 +111,17 @@ module.exports = function (data) {
$('img').each(function () {
const $img = $(this);
const src = $img.attr('src');
const $parents = $img.parents();

// assets & post_asset_folder
src && $img.attr('src', uriReplacer(src, assetPath));

// definitely a block img
if (!$parents.length || !$parents.eq($parents.length - 1).text().trim()) {
if (
this.root // {% img %}
|| (this.parent.tagName === 'p' && !$(this.parent).text().trim()) // \n![]()\n
|| (this.parent.tagName === 'figure') // <figure><img></figure>
) {
// mark as zoomable
$img.attr('data-zoomable', '');

// wrap img to behave as a block
(!$parents.length ? $img : $parents.eq($parents.length - 1)).wrap(img);
$img.addClass('article-img');
}
});

Expand Down
4 changes: 2 additions & 2 deletions lib/generator/theme.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { md5 } = require('../utils');
const generateTheme = require('../../source/_theme.js').default;
const { $appearance } = require('../../source/_theme.js');

module.exports = function () {
const theme = this.theme.config;
const data = generateTheme(theme.appearance);
const data = $appearance(theme.appearance);

theme.runtime.themeHash = md5(data);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-inside",
"version": "2.3.0-beta.3",
"version": "2.3.0-rc.0",
"description": "❤️ SPA, flat and clean theme for Hexo.",
"scripts": {
"test": "jasmine --config=test/jasmine.json"
Expand Down
2 changes: 1 addition & 1 deletion source/_resources.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"styles":["styles.6413cb5fd384752f1714.css"],"scripts":["runtime.9c308a63d02029c20228.js","polyfills-es5.613d1909ec381c0aefb7.js","polyfills.23aa31104b29f3163090.js"],"locales":{"en":"main.c0d55e7428280128d494.en.js","zh-Hant":"main.12166a654353e0a82d68.zh-Hant.js","zh-Hans":"main.3a9ad2f49fd8634e7fa0.zh-Hans.js","ja":"main.e01c85758301d20058a7.ja.js"}}
{"styles":["styles.b052e0427aa70b7d0587.css"],"scripts":["runtime.9c308a63d02029c20228.js","polyfills-es5.613d1909ec381c0aefb7.js","polyfills.23aa31104b29f3163090.js"],"locales":{"ja":"main.1c6c0dbb8fec445fc42a.ja.js","en":"main.7c07007d02c08b471cdf.en.js","zh-Hant":"main.9d756d57e227aba70f33.zh-Hant.js","zh-Hans":"main.d55b8d92fb07c381cd17.zh-Hans.js"}}
2 changes: 1 addition & 1 deletion source/_theme.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion source/main.12166a654353e0a82d68.zh-Hant.js

This file was deleted.

1 change: 1 addition & 0 deletions source/main.1c6c0dbb8fec445fc42a.ja.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion source/main.3a9ad2f49fd8634e7fa0.zh-Hans.js

This file was deleted.

1 change: 1 addition & 0 deletions source/main.7c07007d02c08b471cdf.en.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions source/main.9d756d57e227aba70f33.zh-Hant.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion source/main.c0d55e7428280128d494.en.js

This file was deleted.

1 change: 1 addition & 0 deletions source/main.d55b8d92fb07c381cd17.zh-Hans.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion source/main.e01c85758301d20058a7.ja.js

This file was deleted.

24 changes: 0 additions & 24 deletions source/styles.6413cb5fd384752f1714.css

This file was deleted.

24 changes: 24 additions & 0 deletions source/styles.b052e0427aa70b7d0587.css

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions test/scripts/filters/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ describe('post', function () {
const data = {
layout: 'post',
excerpt: '',
content: `<p><img></p><p>img<img></p><p><img><img></p>`,
content: `<p><img></p><p>img<img></p><p><img><img></p><figure><img></figure>`,
};

post.call(this.ctx, data);

expect(data.content.replace(/\=\"\"/g, '')).toBe(
'<div class="article-img"><p><img data-zoomable></p></div>' +
'<p><img class="article-img"></p>' +
'<p>img<img></p>' +
'<div class="article-img"><p><img data-zoomable><img data-zoomable></p></div>');
'<p><img class="article-img"><img class="article-img"></p>' +
'<figure><img class="article-img"></figure>');
});

it('add additional tag for script', function () {
Expand Down Expand Up @@ -169,7 +170,7 @@ describe('post', function () {

post.call(this.ctx, data);
expect(data.thumbnail).toBe('https://sample.com/img/sample.jpg?q=80')
expect(data.content).toBe('<img src="https://sample.com/img/sample.jpg?q=80">')
expect(data.content).toBe('<img src="https://sample.com/img/sample.jpg?q=80" class="article-img">')

data.layout = 'page'
post.call(this.ctx, data);
Expand All @@ -184,42 +185,41 @@ describe('post', function () {
layout: 'post',
thumbnail: 'data:image',
excerpt: '',
content: '<img src="data:image">',
content: '<p>inline<img src="data:image"></p>',
};

post.call(this.ctx, data);
post.call(this.ctx, { ...data });

expect(data.thumbnail).toBe('data:image')
expect(data.content).toBe('<img src="data:image">')
expect(data.content).toBe('<p>inline<img src="data:image"></p>')
});

it('escape with absolute path', function () {
const data = {
layout: 'post',
thumbnail: 'https://abc.com',
excerpt: '',
content: '<img src="https://abc.com">',
content: '<p>inline<img src="https://abc.com"></p>',
};

post.call(this.ctx, data);

expect(data.thumbnail).toBe('https://abc.com')
expect(data.content).toBe('<img src="https://abc.com">')
expect(data.content).toBe('<p>inline<img src="https://abc.com"></p>')
});

it('parses color', function () {
const data = {
layout: 'post',
thumbnail: 'img/sample.jpg #000',
excerpt: '',
content: '<img src="img/sample.jpg">',
content: '',
};

post.call(this.ctx, data);

expect(data.thumbnail).toBe('https://sample.com/img/sample.jpg?q=80')
expect(data.color).toBe('#000')
expect(data.content).toBe('<img src="https://sample.com/img/sample.jpg?q=80">')
});

it('don\'t parses color when `color` is specified', function () {
Expand All @@ -235,6 +235,6 @@ describe('post', function () {

expect(data.thumbnail).toBe('https://sample.com/img/sample.jpg?q=80')
expect(data.color).toBe('#fff')
expect(data.content).toBe('<img src="https://sample.com/img/sample.jpg?q=80">')
expect(data.content).toBe('<img src="https://sample.com/img/sample.jpg?q=80" class="article-img">')
});
});

0 comments on commit 0f75794

Please sign in to comment.