diff options
Diffstat (limited to '')
-rw-r--r-- | public/js/extra.js | 16 | ||||
-rw-r--r-- | public/js/history.js | 32 |
2 files changed, 34 insertions, 14 deletions
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]; |