forked from zutrinken/attila
-
Notifications
You must be signed in to change notification settings - Fork 1
/
page-memos.hbs
114 lines (103 loc) · 4.29 KB
/
page-memos.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{{!< default}} {{! Everything inside the #post tags pulls data from the post }} {{#post}} <header class="post-header">
<div class="inner">
<h1 class="post-title">{{{title}}}</h1>
</div>
</header>
<main class="content" role="main">
<article class="{{post_class}}">
<div class="inner">
<section class="post-content">
{{content}}
<ul class="talks">
</ul>
</section>
</div>
</article>
</main>
{{/post}}
<script type="text/x-tmpl" id="tmpl-memos">
{% for (var i=0; i<o.data.length; i++) { %}
<li class="timeline page-1">
<div class="talks__avatar"><img src="https://cravatar.cn/avatar/cc38267b10cc25dfc62209f8ca34589e?d=identicon" alt="" /></div>
<div class="talks__content">
<div class="talks__text">
<p>{%# (o.data[i].content) %}</p>
<div class="talks__imgs">
{% if (!!o.data[i].imgs) { %}
{% for (var b=0; b<o.data[i].imgs.length; b++) { %}
{%# o.data[i].imgs[b] %}
{% } %}
{% } %}
</div>
</div>
<div class="talks__meta"><small class="talks__date">{%= new Date(o.data[i].createdTs * 1000).toLocaleString() %}</small></div>
</div>
</li>
{% } %}
</script>
{{#contentFor "scripts"}}
{{#if @custom.memos_url}}
<script>
$(document).ready(function () {
var url = "{{{ @custom.memos_url }}}";
const CODE_BLOCK_REG = /```(\S*?)\s([\s\S]*?)```(\n?)/;
const TODO_LIST_REG = /- \[ \] ([\S ]+)(\n?)/g;
const DONE_LIST_REG = /- \[x\] ([\S ]+)(\n?)/g;
const ORDERED_LIST_REG = /(\d+)\. ([\S ]+)(\n?)/g;
const UNORDERED_LIST_REG = /[*-] ([\S ]+)(\n?)/g;
const PARAGRAPH_REG = /^([\S ]*)(\n?)/mg;
const TAG_REG = /#([^\s#]+?) /g;
const IMAGE_OLD_REG = /!\[.*?\]\(\/([a-z]\/[a-z]\/.+?)\)/g;
const IMAGE_REG = /!\[.*?\]\((.+?)\)/g;
const LINK_REG = /\[(.*?)\]\((.+?)\)/g;
const LINK_BILIBILI_REG = /\[(.*?)\]\((.+?)\)/g;
const MARK_REG = /@\[([\S ]+?)\]\((\S+?)\)/g;
const BOLD_REG = /\*\*([\S ]+)\*\*/g;
const EMPHASIS_REG = /\*([\S ]+)\*/g;
const PLAIN_LINK_REG = /((ht|f)tps?:\/\/[\w\-]+\.[\w\-]+[\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#]) /g;
const INLINE_CODE_REG = /`([\S ]+?)`/g;
const PLAIN_TEXT_REG = /([\S ]+)/g;
const QUOTE_REG = /^>\s+(.+)(\n?)/mg;
const MARK_IMG_REG = /^(.*)(\n\!\[)/;
$.getJSON(url, function(data,status,xhr){
data['url'] = this.url.match(/https:\/\/([^\/]+)\//i)[1];
$(data.data).each(function(i,d){
d.content = d.content.replace(/([\u4e00-\u9fa5])([A-Za-z0-9?.,;[\]]+)/g, "$1 $2")
.replace(/([A-Za-z0-9?.,;[\]]+)([\u4e00-\u9fa5])/g, "$1 $2")
.replace(TODO_LIST_REG, "<p><span class='todo-block todo' data-value='TODO'></span>$1</p>$2")
.replace(DONE_LIST_REG, "<p><span class='todo-block done' data-value='DONE'>✓</span>$1</p>$2")
.replace(ORDERED_LIST_REG, "<p><span class='ol-block'>$1.</span>$2 $3</p>")
.replace(UNORDERED_LIST_REG, "<p><span class='ul-block'>•</span>$1 $2</p>")
.replace(QUOTE_REG, "<blockquote>$1</blockquote>")
.replace(CODE_BLOCK_REG, "<pre><code lang='$1'>\n$2</code></pre>$3")
//.replace(PARAGRAPH_REG, "<p>$1</p>$2")
//.replace(MARK_IMG_REG, "<p>$1</p>$2")
.replace(IMAGE_OLD_REG, "<img class='img old square' src='//"+data.url+"/$1' />")
.replace(IMAGE_REG, "<img class='img square' src='$1' />")
.replace(MARK_REG, "<span class='memo-link-text' data-value='$2'>$1</span>")
.replace(BOLD_REG, "<strong>$1</strong>")
.replace(EMPHASIS_REG, "<em>$1</em>")
.replace(LINK_REG, "<a class='link' target='_blank' rel='noreferrer' href='$2'>$1</a>")
//.replace(INLINE_CODE_REG, "<code>$1</code>")
.replace(PLAIN_LINK_REG, "<a class='link' target='_blank' rel='noreferrer' href='$1'>$1</a> ")
.replace(TAG_REG, "<span class='tag-span'>#$1</span> ")
.replace(PLAIN_TEXT_REG, "$1")
d.imgs = [];
$(d.resourceList).each(function(ii,b){
d.imgs[ii] = "<img class='img' src='//"+ data.url + "/o/r/" + b.id + "/" + b.filename +"' />";
})
});
$('.talks').html(tmpl('tmpl-memos', data))
//处理老的图片格式
//添加灯箱
$('.talks__imgs img').simplebox({
fadeSpeed: 300, // default is 400ms, applied to all fade animations in the plugin
darkMode: true, // default is false
postfix: "_full", // default is ""
});
codestyling();
});
});
</script>
{{/if}}
{{/contentFor}}