summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-06-21 21:42:03 +0800
committerCheng-Han, Wu2016-06-21 21:42:03 +0800
commit558304ff62a648e604b03afe3372ef9566aea850 (patch)
treef01521782685784508e4e5017d25a9c6b7768d06 /public
parentad6982e77e1948bd7b74538af0c5a24120a38370 (diff)
Update to support new metadata: title, description, tags and google-analytics (GA) and refactor render publish slide response function
Diffstat (limited to 'public')
-rw-r--r--public/docs/yaml-metadata.md35
-rw-r--r--public/js/extra.js16
-rw-r--r--public/js/history.js32
-rw-r--r--public/views/ga.ejs18
-rw-r--r--public/views/pretty.ejs7
-rw-r--r--public/views/slide.ejs8
6 files changed, 100 insertions, 16 deletions
diff --git a/public/docs/yaml-metadata.md b/public/docs/yaml-metadata.md
index 5fc6e1b8..539410c8 100644
--- a/public/docs/yaml-metadata.md
+++ b/public/docs/yaml-metadata.md
@@ -18,6 +18,39 @@ YAML metas
Replace the "YAML metas" in this section with any YAML options as below.
You can also refer to this note's source code.
+title
+---
+This option will set the note title which prior than content title.
+
+> default: not set
+
+**Example**
+```xml
+title: meta title
+```
+
+description
+---
+This option will set the note description.
+
+> default: not set
+
+**Example**
+```xml
+description: meta description
+```
+
+tags
+---
+This option will set the tags which prior than content tags.
+
+> default: not set
+
+**Example**
+```xml
+tags: features, cool, updated
+```
+
robots
---
This option will give below meta in the note head meta:
@@ -26,7 +59,7 @@ This option will give below meta in the note head meta:
```
So you can prevent any search engine index your note by set `noindex, nofollow`.
-> default: not
+> default: not set
**Example**
```xml
diff --git a/public/js/extra.js b/public/js/extra.js
index 953770be..e67eee53 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -43,12 +43,16 @@ function updateLastChangeUser() {
//get title
function getTitle(view) {
- var h1s = view.find("h1");
var title = "";
- if (h1s.length > 0) {
- title = h1s.first().text();
+ if (md && md.meta && md.meta.title && (typeof md.meta.title == "string" || typeof md.meta.title == "number")) {
+ title = md.meta.title;
} else {
- title = null;
+ var h1s = view.find("h1");
+ if (h1s.length > 0) {
+ title = h1s.first().text();
+ } else {
+ title = null;
+ }
}
return title;
}
@@ -93,7 +97,7 @@ function parseMeta(md, edit, view, toc, tocAffix) {
spellcheck = meta.spellcheck;
}
//text language
- if (lang) {
+ if (lang && typeof lang == "string") {
view.attr('lang', lang);
toc.attr('lang', lang);
tocAffix.attr('lang', lang);
@@ -107,7 +111,7 @@ function parseMeta(md, edit, view, toc, tocAffix) {
edit.removeAttr('lang', lang);
}
//text direction
- if (dir) {
+ if (dir && typeof dir == "string") {
view.attr('dir', dir);
toc.attr('dir', dir);
tocAffix.attr('dir', dir);
diff --git a/public/js/history.js b/public/js/history.js
index 9bdca709..0840580d 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -202,28 +202,44 @@ function writeHistoryToStorage(view) {
}
}
+if (!Array.isArray) {
+ Array.isArray = function(arg) {
+ return Object.prototype.toString.call(arg) === '[object Array]';
+ };
+}
+
function renderHistory(view) {
var title = renderFilename(view);
var tags = [];
var rawtags = [];
- view.find('h6').each(function (key, value) {
- if (/^tags/gmi.test($(value).text())) {
- var codes = $(value).find("code");
- for (var i = 0; i < codes.length; i++)
- rawtags.push(codes[i]);
+ if (md && md.meta && md.meta.tags && (typeof md.meta.tags == "string" || typeof md.meta.tags == "number")) {
+ var metaTags = ('' + md.meta.tags).split(',');
+ for (var i = 0; i < metaTags.length; i++) {
+ var text = metaTags[i].trim();
+ if (text) rawtags.push(text);
}
- });
+ } else {
+ view.find('h6').each(function (key, value) {
+ if (/^tags/gmi.test($(value).text())) {
+ var codes = $(value).find("code");
+ for (var i = 0; i < codes.length; i++) {
+ var text = codes[i].innerHTML.trim();
+ if (text) rawtags.push(text);
+ }
+ }
+ });
+ }
for (var i = 0; i < rawtags.length; i++) {
var found = false;
for (var j = 0; j < tags.length; j++) {
- if (tags[j] == rawtags[i].innerHTML) {
+ if (tags[j] == rawtags[i]) {
found = true;
break;
}
}
if (!found)
- tags.push(rawtags[i].innerHTML);
+ tags.push(rawtags[i]);
}
//console.debug(tags);
var id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
diff --git a/public/views/ga.ejs b/public/views/ga.ejs
new file mode 100644
index 00000000..180832d1
--- /dev/null
+++ b/public/views/ga.ejs
@@ -0,0 +1,18 @@
+<% if(typeof GA !== 'undefined' && GA) { %>
+<script>
+(function (i, s, o, g, r, a, m) {
+ i['GoogleAnalyticsObject'] = r;
+ i[r] = i[r] || function () {
+ (i[r].q = i[r].q || []).push(arguments)
+ }, i[r].l = 1 * new Date();
+ a = s.createElement(o),
+ m = s.getElementsByTagName(o)[0];
+ a.async = 1;
+ a.src = g;
+ m.parentNode.insertBefore(a, m)
+})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
+
+ga('create', '<%- GA %>', 'auto');
+ga('send', 'pageview');
+</script>
+<% } %> \ No newline at end of file
diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs
index 0a541107..5ba2e8e1 100644
--- a/public/views/pretty.ejs
+++ b/public/views/pretty.ejs
@@ -11,6 +11,9 @@
<% if(typeof robots !== 'undefined' && robots) { %>
<meta name="robots" content="<%- robots %>">
<% } %>
+ <% if(typeof description !== 'undefined' && description) { %>
+ <meta name="description" content="<%- description %>">
+ <% } %>
<title><%- title %></title>
<link rel="icon" type="image/png" href="<%- url %>/favicon.png">
<link rel="apple-touch-icon" href="<%- url %>/apple-touch-icon.png">
@@ -117,4 +120,6 @@
<script src="<%- url %>/js/common.js" defer></script>
<script src="<%- url %>/js/extra.js" defer></script>
<script src="<%- url %>/js/render.js" defer></script>
-<script src="<%- url %>/js/pretty.js" defer></script> \ No newline at end of file
+<script src="<%- url %>/js/pretty.js" defer></script>
+
+<%- include ga %> \ No newline at end of file
diff --git a/public/views/slide.ejs b/public/views/slide.ejs
index 27ccfdf8..3fe30944 100644
--- a/public/views/slide.ejs
+++ b/public/views/slide.ejs
@@ -5,6 +5,12 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="mobile-web-app-capable" content="yes">
+ <% if(typeof robots !== 'undefined' && robots) { %>
+ <meta name="robots" content="<%- robots %>">
+ <% } %>
+ <% if(typeof description !== 'undefined' && description) { %>
+ <meta name="description" content="<%- description %>">
+ <% } %>
<title><%- title %></title>
<link rel="icon" type="image/png" href="<%- url %>/favicon.png">
<link rel="apple-touch-icon" href="<%- url %>/apple-touch-icon.png">
@@ -83,3 +89,5 @@
</script>
</body>
</html>
+
+<%- include ga %> \ No newline at end of file