Skip to content

Commit

Permalink
feat(Version 2.0.7): ✨ Add two settings
Browse files Browse the repository at this point in the history
  • Loading branch information
syfxlin committed Sep 8, 2019
1 parent 5756aef commit f7c6cda
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
4 changes: 3 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ function origami_frontend_config()
'lastInspirationTime' => get_the_time('U', get_posts([
'numberposts' => 1,
'post_type' => 'inspiration'
])[0])
])[0]),
'tocLevel' => get_option('origami_toc_level', 'h1,h2,h3'),
'copyAddCopyright' => get_option('origami_copy_add_copyright', 'ncode')
];
echo "<script>window.origamiConfig = JSON.parse('" .
json_encode($config) .
Expand Down
30 changes: 30 additions & 0 deletions include/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ public function admin_init()
);

// 其他
register_setting('origami_fun', 'origami_copy_add_copyright');
register_setting('origami_fun', 'origami_toc_level');
register_setting('origami_fun', 'origami_canvas_nest');
register_setting('origami_fun', 'origami_workbox');
register_setting('origami_fun', 'origami_lazyload');
Expand All @@ -638,6 +640,34 @@ public function admin_init()
[&$this, 'origami_section'],
'origami_fun'
);
add_settings_field(
'origami_copy_add_copyright',
__('复制时添加版权信息', 'origami'),
[&$this, 'settings_field_input_text'],
'origami_fun',
'origami_fun_other',
[
'field' => 'origami_copy_add_copyright',
'value' => 'ncode',
'type' => 'text',
'description' =>
'all表示不管复制什么内容都会添加版权信息,ncode表示除代码部分外复制内容会添加版权信息,none表示不启用复制添加版权信息的功能'
]
);
add_settings_field(
'origami_toc_level',
__('生成目录的级别', 'origami'),
[&$this, 'settings_field_input_text'],
'origami_fun',
'origami_fun_other',
[
'field' => 'origami_toc_level',
'value' => 'h1,h2,h3',
'type' => 'text',
'description' =>
'设置生成目录的级别(文章目录),默认为h1,h2,h3'
]
);
add_settings_field(
'origami_canvas_nest',
__('Canvas-Nest背景', 'origami'),
Expand Down
10 changes: 7 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,18 +839,19 @@ origami.buildFooterTime = function() {
};

origami.initTocbot = function() {
let tocLevel = origamiConfig.tocLevel ? origamiConfig.tocLevel : 'h1, h2, h3';
let content = document.querySelector('.s-post-content,.p-post-content');
let i = 0;
if (!content || !content.querySelectorAll('h1, h2, h3')) return;
content.querySelectorAll('h1, h2, h3').forEach(function(item) {
if (!content || !content.querySelectorAll(tocLevel)) return;
content.querySelectorAll(tocLevel).forEach(function(item) {
item.id = 'title-' + i;
i++;
});
let offset = document.querySelector('.ori-header').clientHeight;
tocbot.init({
tocSelector: '.toc',
contentSelector: '.s-post-content,.p-post-content',
headingSelector: 'h1, h2, h3',
headingSelector: tocLevel,
headingsOffset: offset + 21,
onClick: function(e) {
window.scrollTo({
Expand Down Expand Up @@ -1391,7 +1392,10 @@ origami.paperPlane = function() {
};

origami.copy = function() {
let setting = origamiConfig.copyAddCopyright;
let inner = function(e) {
if (setting === 'none') return;
if (setting === 'ncode' && e.target.nodeName === 'CODE') return;
e.preventDefault();
let html =
window.getSelection().toString() +
Expand Down
15 changes: 11 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Theme URI: https://blog.ixk.me/theme-origami.html
Author: Otstar Lin
Author URI: https://www.ixk.me
Description: 简约平面化风格的主题
Version: 2.0.6
Version: 2.0.7
License: GNU General Public License v3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Tags: black,cyan-blue,flat,responsive
Expand Down Expand Up @@ -824,7 +824,7 @@ body.menu-active .ori-footer {
}

.post-list .card-body {
font-size: 0.7rem;
font-size: 0.75rem;
color: #3b4351;
}

Expand Down Expand Up @@ -977,7 +977,7 @@ body.menu-active .ori-footer {
background-color: rgba(255, 255, 255, 0.7);
box-shadow: 0 1px 20px -6px rgba(0, 0, 0, 0.2);
margin-top: 1rem;
font-size: 0.7rem;
font-size: 0.75rem;
}

.sidebar-widget #searchform label {
Expand Down Expand Up @@ -1106,10 +1106,17 @@ body.menu-active .ori-footer {

.p-post-content,
.s-post-content {
font-size: 0.7rem;
font-size: 0.75rem;
font-weight: 400;
color: #454545;
word-break: break-word;
margin-top: 1rem;
line-height: 1.8;
}

.s-post-content p,
.p-post-content p {
margin: 0 0 0.6rem;
}

.s-post-content h1,
Expand Down

0 comments on commit f7c6cda

Please sign in to comment.