Skip to content

Commit

Permalink
✨ 增加代码块行号显隐配置等
Browse files Browse the repository at this point in the history
  • Loading branch information
esofar committed Dec 5, 2020
1 parent c2bd5c9 commit bc92e90
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion dist/silence.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/silence.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/consts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const options = {
defaultTheme: 'a',
navbars: [],
showNavAdmin: true,
hljsln: false,
catalog: {
enable: false,
index: true,
Expand Down
42 changes: 18 additions & 24 deletions src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
--border-color: #eef2f8;
--catalog-bg-color: #fff;
--panel-bg-color: #f8f8f8;
--contents-bg-color: #fff;
--code-bg-color: #f1f1f1;
}

Expand All @@ -17,7 +16,6 @@
--border-color: #2f2f2f;
--catalog-bg-color: #252525;
--panel-bg-color: #252525;
--contents-bg-color: #343232;
--code-bg-color: #3a3a3a;
}

Expand Down Expand Up @@ -148,7 +146,6 @@ a {
left: 0;
margin: 0 auto;
border-top: 0px;
opacity: 0.95;
border-bottom: 1px var(--border-color) solid;
padding-bottom: 0px;
display: block;
Expand Down Expand Up @@ -223,7 +220,7 @@ a {

.open {
transform: rotate(180deg) scaleX(-1);
transition: 0.3s;
transition-duration: 0.3s;
}

.esa-sub-navs {
Expand All @@ -237,14 +234,14 @@ a {
border-top: 0px solid transparent;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid var(--contents-bg-color);
border-bottom: 8px solid var(--blog-bg-color);
width: 0px;
position: relative;
left: calc(50% - 8px);
}

ul {
background-color: var(--contents-bg-color);
background-color: var(--blog-bg-color);
border-radius: 4px;
box-shadow: 0 1px 15px rgba(27, 31, 35, 0.15);
padding: 10px;
Expand Down Expand Up @@ -489,21 +486,16 @@ a {
line-height: 30px;
white-space: nowrap;
overflow: hidden;
transition: all 0.5s;
text-overflow: ellipsis;
list-style: inside;

&:hover {
margin-left: 7px;
}
list-style: none;
}

#sidebar_recentposts li,
#sidebar_topviewedposts li,
#sidebar_topcommentedposts li,
#sidebar_topdiggedposts li {
font-size: 15px;
padding: 10px 0px;
padding: 7px 0px;
transition: all 0.3s;
text-align: justify;
border-bottom: 1px solid var(--border-color);
Expand Down Expand Up @@ -682,7 +674,7 @@ a {
}

a {
border-bottom: 1px solid var(--text-color);
border-bottom: 1px dotted var(--text-color);
padding: 2px 5px;
font-size: 14px;
margin-top: 10px;
Expand All @@ -693,7 +685,7 @@ a {
}

&:hover {
border-bottom: 1px solid var(--theme-color);
border-bottom: 1px dotted var(--theme-color);
}
}
}
Expand Down Expand Up @@ -818,25 +810,30 @@ a {
}

table {
font-size: 14px;
border-collapse: collapse;
border-spacing: 0;
empty-cells: show;
border: 1px solid var(--border-color);
font-size: 15px;
width: 100%;
margin: 15px 0px;
display: block;
overflow-x: auto;
border: none;

&::-webkit-scrollbar {
height: 4px !important;
}

th {
background: var(--panel-bg-color);
border: 1px solid var(--border-color);
white-space: nowrap;
font-weight: 400;
padding: 6px 15px;
min-width: 100px;
}

td {
border: 1px solid var(--border-color);
padding: 6px 15px;
min-width: 100px;
}
}

Expand Down Expand Up @@ -1145,7 +1142,7 @@ a {
.feedback_area_title {
font-size: 20px;
border-bottom: 1px solid var(--border-color);
margin-bottom: 15px;
margin: 20px 0px;
padding-bottom: 5px;
}

Expand Down Expand Up @@ -1261,7 +1258,4 @@ a {

::-webkit-scrollbar-thumb {
background-color: var(--text-color);
&:hover {
background-color: var(--theme-color);
}
}
11 changes: 8 additions & 3 deletions src/modules/hljsLineNumber/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import "./index.less";
import options from '@/consts/options';

function buildHljsLineNumber() {
let $codes = $('.postBody .cnblogs-markdown').find('pre code');
if (!$codes.length) {
return false;
}

$.each($codes, (_, code) => {
if (!$(code).hasClass('hljsln')) {
var html = $(code).html();
html = addLineNumbersFor(html);
$(code).html(html).addClass('hljsln');
$(code).addClass('hljsln');
if (!options.hljsln) {
$(code).addClass('ln-hide');
return true;
}
$(code).html(addLineNumbersFor($(code).html()));
var $lastNum = $('span[data-num]:last');
if (!$lastNum.html()) {
$lastNum.remove();
Expand Down
8 changes: 6 additions & 2 deletions src/modules/hljsLineNumber/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
.cnblogs-markdown .hljsln {
display: block;
overflow-x: auto;
padding: 0.5em 1em 0.5em 3em !important;
padding: 0.7em 1em 0.7em 3em !important;
background: #2b2b2b !important;
border: 1px solid #2c2a2a !important;
color: #bababa;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace !important;
font-size: 15px !important;

&::-webkit-scrollbar {
height: 5px;
height: 4px;
}
}

.cnblogs-markdown .hljs.ln-hide {
padding: 0.7em 1em 0.7em 1em !important;
}

.ln-bg {
position: absolute;
z-index: 1;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/postContents/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./index.less";
import options from '@/consts/options';
import { isPostPage } from '@consts/tools';

function buildPostContents() {
const config = options.catalog;
Expand All @@ -18,7 +19,6 @@ function buildPostContents() {
$('body').append(`<div class="esa-contents noactive"></div>`);

if (config.active) {
$toolbar.find('.bars').trigger('click');
$toolbar.find('.contents').trigger('click');
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/postContents/index.less
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.esa-contents {
box-shadow: -2px 0 3px rgba(0, 0, 0, 0.1);
position: fixed;
top: 0;
right: 0;
bottom: 0;
background-color: var(--contents-bg-color);
background-color: var(--blog-bg-color);
border-left: 1px solid var(--border-color);
overflow-y: auto;
user-select: none;
padding: 1rem 0;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/postSponsor/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/modules/toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ function buildToolbar() {
$('#home').css({ "width": "100%" });
showcontents = false;
}


});

if (isPostPage()) {
$toolbar.find('.bars').trigger('click');
}
}

export default buildToolbar;
3 changes: 2 additions & 1 deletion src/templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
defaultMode: 'auto',
defaultTheme: 'c',
showNavAdmin: true,
hljsln: false,
navbars: [{
title: '标签',
url: 'https://www.cnblogs.com/esofar/tag/'
Expand All @@ -95,7 +96,7 @@
catalog: {
enable: true,
index: true,
active: false,
active: true,
levels: ['h2', 'h3', 'h4'],
},
signature: {
Expand Down

0 comments on commit bc92e90

Please sign in to comment.