diff --git a/Bloggie/Core/Core.js b/Bloggie/Core/Core.js index 42ace29..828581e 100644 --- a/Bloggie/Core/Core.js +++ b/Bloggie/Core/Core.js @@ -49,12 +49,8 @@ var bloggie = (function () { } } - if (!localStorage.getItem("bloggie-base")) { - base = JSON.parse(get('./Bloggie/Core/base.json')); - localStorage.setItem("bloggie-base", JSON.stringify(base)); - } else { - base = JSON.parse(localStorage.getItem("bloggie-base")); - } + base = bloggie_init; + delete window.bloggie_init; window.onerror = function (message, source, lineno, colno, error) { Err('Message:' + message + '\nSource:' + source + '\nLineno:' + lineno + '\nColno:' + colno + '\nError:' + error); @@ -69,7 +65,6 @@ var bloggie = (function () { var html = document.documentElement; html.lang = base.lang || 'en-US'; html.dir = base.dir || 'ltr'; - swloader(); if (jslist.loading) { var scripts = Object.keys(jslist.loading).length; for (var n = 1; n <= scripts; n++) { @@ -246,14 +241,69 @@ var bloggie = (function () { document.getElementById('bloggie-main').appendChild(aie); }; - function loadlist() { + function loadlist(filter = bloggie.custom.listfilter, rest = bloggie.custom.listfilter_rest) { document.getElementById('bloggie-main').innerHTML = ''; var div = document.createElement('div'); div.id = 'bloggie-list'; - var art = Object.keys(articlelist); + var lc = JSON.parse(JSON.stringify(articlelist)); + var art = Object.keys(lc); var n = art.length; - while (n--) { - div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + if (typeof(filter) === 'string') { + while (n--) { + if (articlelist[n + 1][filter]) { + lc[n + 1].used = true; + div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + if (rest) { + n = art.length; + while (n--) { + if (!lc[n + 1].used) div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + } else if (typeof(filter) === 'function') { + while (n--) { + if (filter(articlelist[n + 1])) { + lc[n + 1].used = true; + div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + if (rest) { + n = art.length; + while (n--) { + if (!lc[n + 1].used) div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + } else if (Array.isArray(filter)) { + filter.forEach((checker, index) => { + var n = art.length; + if (typeof(checker) === 'string') { + while (n--) { + if (articlelist[n + 1][checker]) { + lc[n + 1].used = true; + div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + } else if (typeof(checker) === 'function') { + while (n--) { + if (checker(articlelist[n + 1])) { + lc[n + 1].used = true; + div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + } else console.warn(`传入的数组中第${index}个元素的格式不受支持,已自动忽略。`); + if (rest) { + n = art.length; + while (n--) { + if (!lc[n + 1].used) div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } + } + }); + } else { + if (filter) console.warn(`传入的参数格式不受支持,已自动回退到默认处理。`); + while (n--) { + div.appendChild((bloggie.custom.command.listmaker || listmaker)(articlelist[n + 1], art[n])); + } } document.getElementById('bloggie-main').appendChild(div); } @@ -265,18 +315,6 @@ var bloggie = (function () { return div; } - async function swloader() { - if (navigator.serviceWorker && base.sw.Supported) { - try { - await navigator.serviceWorker.register(base.sw.path, base.sw.options); - await navigator.serviceWorker.ready; - } - catch (e) { - Err(e); - } - } - } - return bloggie; }()); \ No newline at end of file diff --git a/Bloggie/Core/base.js b/Bloggie/Core/base.js new file mode 100644 index 0000000..a293040 --- /dev/null +++ b/Bloggie/Core/base.js @@ -0,0 +1,199 @@ +'use strict'; +window.bloggie_init = { + "name": "DaleZ 的 Blog", + "lang": "zh-CN", + "dir": "ltr", + "jslist": { + "loading": { + "1": { + "path": "./Bloggie/js/init-helper.js", + "options": null + }, + "2": { + "path": "./Bloggie/js/PWAify.js", + "options": null + }, + "3": { + "path": "./Bloggie/js/CSS.js", + "options": null + }, + "4": { + "path": "./Bloggie/js/customloading.js", + "options": null + } + }, + "loaded": { + "1": { + "path": "https://cdnjs.cloudflare.com/ajax/libs/marked/5.0.2/marked.min.js?ServiceWorker=cachefirst", + "options": { + "crossorigin": "anonymous" + }, + "JoinWaitlist": true + }, + "2": { + "path": "./Bloggie/js/HighLight/highlight.min.js?ServiceWorker=cachefirst", + "options": null, + "JoinWaitlist": true + }, + "3": { + "path": "https://cdn.jsdelivr.net/npm/marked-gfm-heading-id@3.0.3/lib/index.umd.min.js?ServiceWorker=cachefirst", + "options": { + "crossorigin": "anonymous" + }, + "JoinWaitlist": true + }, + "4": { + "path": "https://cdn.jsdelivr.net/npm/marked-mangle@1.0.1/lib/index.umd.min.js?ServiceWorker=cachefirst", + "options": { + "crossorigin": "anonymous" + }, + "JoinWaitlist": true + }, + "5": { + "path": "https://cdn.jsdelivr.net/npm/marked-highlight@2.0.0/lib/index.umd.min.js?ServiceWorker=cachefirst", + "options": { + "crossorigin": "anonymous" + }, + "JoinWaitlist": true + }, + "6": { + "path": "./Bloggie/js/marked-init.js?ServiceWorker=cachefirst", + "options": null, + "JoinWaitlist": true + }, + "7": { + "path": "./Bloggie/js/custom.js", + "options": null, + "JoinWaitlist": true + }, + "8": { + "path": "./Bloggie/js/titlebar.js", + "options": null, + "JoinWaitlist": true + }, + "9": { + "path": "https://cdn.jsdelivr.net/npm/msemoji@1.1.2/dist/msemoji.min.js?ServiceWorker=cachefirst", + "options": { + "crossorigin": "anonymous" + }, + "JoinWaitlist": true + }, + "10": { + "path": "https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.umd.js?ServiceWorker=cachefirst", + "options": { + "crossorigin": "anonymous" + }, + "JoinWaitlist": true + }, + "11": { + "path": "https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.12.0/lottie.min.js?ServiceWorker=cachefirst", + "options": { + "defer": true, + "crossorigin": "anonymous" + } + }, + "12": { + "path": "./Bloggie/js/component.js", + "options": null, + "JoinWaitlist": true + }, + "13": { + "path": "./Bloggie/js/swloader.js", + "options": null, + } + } + }, + "articlelist": { + "1": { + "Title": "Test", + "File": "./Bloggie/article/Test.md", + "Comment": true, + "icon": "", + "tags": ['Test1','Test2','Test3'], + "create": "2023-6-14", + "edit": "2023-6-28" + }, + "2": { + "Title": "[测试]Windows 12 是怎么出现的?你知道多少?", + "File": "./Bloggie/article/uselesstext1.md", + "Comment": false, + "tags": ['Test1'] + }, + "3": { + "Title": "[测试]论使用 Windows 的意义", + "File": "./Bloggie/article/uselesstext2.md", + "Comment": false, + "tags": ['Test2'] + }, + "4": { + "Title": "[测试]全面讲解微软战略", + "File": "./Bloggie/article/uselesstext3.md", + "Comment": false, + "tags": ['Test3'] + }, + "5": { + "Title": "微软风音乐不完全集合", + "File": "./Bloggie/article/MSMusic.md", + "Comment": true, + "tags": ['Test1','Test2'] + }, + "6": { + "Title": "本站介绍(尚在编写)", + "File": "./Bloggie/article/Introduce.md", + "Comment": true, + "tags": ['Test2','Test3'], + "Top": true + }, + "7": { + "Title": "Blog Beta 1 更新日志", + "File": "./Bloggie/article/beta1update.md", + "Comment": true, + "tags": ['Test1','Test3'], + "desp": "了解本 Blog 在 Beta 1 的更新内容。", + "icon": "", + "create": "2023-6-28", + "edit": "2023-6-30" + }, + "8": { + "Title": "Blog Beta 2 更新日志", + "File": "./Bloggie/article/beta2update.md", + "Comment": true, + "tags": ['Test1','Test3'], + "desp": "了解本 Blog 在 Beta 2 的更新内容。", + "icon": "", + "create": "2023-7-31" + } + }, + "wait": { + "type": "function", + "content": "(function() {return bloggie.custom.command.customLoadingAnimation();})" + }, + "nav": { + "主页": { + "action": "bloggie.LoadArticle()", + "icon": "./Bloggie/skin/Res/Home.svg" + }, + "目录": { + "action": "bloggie.LoadArticle('list')", + "icon": "./Bloggie/skin/Res/List.svg" + }, + "设置": { + "action": "bloggie.LoadArticle('Settings')", + "icon": "./Bloggie/skin/Res/Setting.svg" + } + }, + "SpecialPage": { + "list": { + "action": "loadlist()", + "Title": "目录" + }, + "Settings": { + "action": "bloggie.custom.command.loadSettings()", + "Title": "设置" + }, + "Main": { + "file": "./Bloggie/article/Main.md", + "Title": "DaleZ 的 Blog" + } + } +}; \ No newline at end of file diff --git a/Bloggie/article/beta2update.md b/Bloggie/article/beta2update.md new file mode 100644 index 0000000..f6e5724 --- /dev/null +++ b/Bloggie/article/beta2update.md @@ -0,0 +1,20 @@ +您好!感谢您参与本博客的测试!本次我们从 Beta 1 版更新到了 Beta 2 版,以下是本次更新内容。 +### 新功能与改进 + +- **_新增功能!_** 目录与查看文章页面现已设计完成,界面已经高度符合 Windows 11 设计原则。 +- **_新增功能!_** 现在本博客引入了标签功能,可通过标签筛选文章,并在目录中查看所有标签。(**注意:** 标签类别尚未完善。) +- **_新增功能!_** 文章现在可查看相关的信息。(**注意:** 并非所有文章都带有信息。) +- **_新增功能!_** 文章现可置顶。 +- 页脚现已更新为符合 Windows 11 设计原则的样式。 +- 当 Service Worker 收到更新时,您现在会收到通知。(**注意:** 在此版本中您可能不会收到消息,但在下一个版本更新时您将看到效果。) + +### 已知问题 + +- 对于某些浏览器的网络策略,加载时间偶尔可能比预期更长,而并非加载失败。继续等待或刷新以完成加载。 +- 同时点击多个导航栏项将导致指示灯错乱。再次点击**一个**导航栏项将恢复指示灯。 +- 较旧的浏览器可能会在多次操作导航栏后使指示灯陷入完全错乱的状态。若发生此情况,请更新您的浏览器。 +- 如果有图片等可能不会立即加载完成的内容,锚点跳转可能无法完全跳转到指定的位置。如果跳转后无法找到内容,尝试略向下移动以找到内容。 +- 查看某些文章时,沉浸式阅读模式可能不可用。 + +**注意:** 建议刷新一遍以便完全升级到 Beta 2。 +我们期待听到您的反馈。向我们报告问题以便本博客变得更好! \ No newline at end of file diff --git a/Bloggie/js/CSS.js b/Bloggie/js/CSS.js index 6ab25c5..1baa2c1 100644 --- a/Bloggie/js/CSS.js +++ b/Bloggie/js/CSS.js @@ -1,31 +1,38 @@ 'use strict'; -var css = document.createElement('link'); -css.href = './Bloggie/skin/CSS/markdown.css'; -css.media = 'all'; -css.rel = 'stylesheet'; -document.head.appendChild(css); -css = document.createElement('link'); -css.href = './Bloggie/skin/CSS/blog.css'; -css.media = 'all'; -css.rel = 'stylesheet'; -document.head.appendChild(css); -css = document.createElement('link'); -css.href = './Bloggie/js/HighLight/styles/github.min.css'; -css.rel = 'stylesheet'; -document.head.appendChild(css); -css = document.createElement('link'); -css.href = './Bloggie/js/HighLight/styles/github-dark.min.css'; -css.media = '(prefers-color-scheme: dark)'; -css.rel = 'stylesheet'; -document.head.appendChild(css); -var css = document.createElement('link'); -css.href = 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css'; -css.media = 'all'; -css.rel = 'stylesheet'; -css.crossorigin = 'anonymous'; -document.head.appendChild(css); -var css = document.createElement('link'); -css.href = './Bloggie/skin/CSS/fancycustomicon.css'; -css.media = 'all'; -css.rel = 'stylesheet'; -document.head.appendChild(css); \ No newline at end of file +(() => { + var css = document.createElement('link'); + css.href = './Bloggie/skin/CSS/markdown.css'; + css.media = 'all'; + css.rel = 'stylesheet'; + document.head.appendChild(css); + css = document.createElement('link'); + css.href = './Bloggie/skin/CSS/blog.css'; + css.media = 'all'; + css.rel = 'stylesheet'; + document.head.appendChild(css); + css = document.createElement('link'); + css.href = './Bloggie/js/HighLight/styles/github.min.css'; + css.rel = 'stylesheet'; + document.head.appendChild(css); + css = document.createElement('link'); + css.href = './Bloggie/js/HighLight/styles/github-dark.min.css'; + css.media = '(prefers-color-scheme: dark)'; + css.rel = 'stylesheet'; + document.head.appendChild(css); + var css = document.createElement('link'); + css.href = 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css'; + css.media = 'all'; + css.rel = 'stylesheet'; + css.crossorigin = 'anonymous'; + document.head.appendChild(css); + var css = document.createElement('link'); + css.href = './Bloggie/skin/CSS/fancycustomicon.css'; + css.media = 'all'; + css.rel = 'stylesheet'; + document.head.appendChild(css); + css = document.createElement('link'); + css.href = './Bloggie/skin/CSS/component.css'; + css.media = 'all'; + css.rel = 'stylesheet'; + document.head.appendChild(css); +})(); \ No newline at end of file diff --git a/Bloggie/js/component.js b/Bloggie/js/component.js new file mode 100644 index 0000000..3eddedc --- /dev/null +++ b/Bloggie/js/component.js @@ -0,0 +1,83 @@ +var DaleZ_listbutton = (function () { + var template = document.implementation.createHTMLDocument(); + template.body.innerHTML = ``; + + function create(title = '', desp = '', other, icon = '') { + var final = template.cloneNode(true); + final.getElementsByClassName('title')[0].innerHTML = title; + final.getElementsByClassName('desp')[0].innerHTML = desp; + final.getElementsByClassName('first')[0].setAttribute('data-icon', icon); + if (!other) { + final.getElementsByClassName('first')[0].removeChild(final.getElementsByClassName('first')[0].lastElementChild) + } else { + if (typeof (other) === 'text') { + final.getElementsByClassName('other')[0].innerHTML = other; + } if (Array.isArray(other)) { + other.forEach(function (value) { + if (typeof(value) === 'text') { + final.getElementsByClassName('other')[0].innerHTML += value; + } else final.getElementsByClassName('other')[0].appendChild(value); + }); + } else { + final.getElementsByClassName('other')[0].appendChild(other); + } + } + return final.getElementsByClassName('first')[0]; + } + + return create; +})(); + +var DaleZ_Tag = (function () { + function isLight(val) { //HEX十六进制颜色值转换为RGB(A)颜色值 + // 16进制颜色值的正则 + var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; + // 把颜色值变成小写 + var color = val.toLowerCase(); + var result = ''; + if (reg.test(color)) { + // 如果只有三位的值,需变成六位,如:#fff => #ffffff + if (color.length === 4) { + var colorNew = "#"; + for (var i = 1; i < 4; i += 1) { + colorNew += color.slice(i, i + 1).concat(color.slice(i, i + 1)); + } + color = colorNew; + } + // 处理六位的颜色值,转为RGB + var colorChange = []; + for (var i = 1; i < 7; i += 2) { + colorChange.push(parseInt("0x" + color.slice(i, i + 2))); + } + var grayLevel = colorChange[0] * 0.299 + colorChange[1] * 0.587 + colorChange[2] * 0.114; + if (grayLevel >= 192) {//浅色模式 + return true; + } else { + return false; + } + } else { + return false; + } + } + + function create(title = '', color = '#036ac4', icon = '', desp) { + var final = document.createElement('button'); + final.className = 'Tag'; + final.innerHTML = title; + final.title = desp || title; + if (!isLight(color)) { + final.style.color = 'white'; + } + final.style.backgroundColor = color; + final.setAttribute('data-icon', icon); + return final; + } + + return create; +})(); \ No newline at end of file diff --git a/Bloggie/js/custom.js b/Bloggie/js/custom.js index e0ba3db..378b191 100644 --- a/Bloggie/js/custom.js +++ b/Bloggie/js/custom.js @@ -1,13 +1,24 @@ 'use strict'; bloggie.custom.command.loadcontentbeforearticle = (ctt) => { if (typeof(ctt.Comment) != 'undefined') { - var r = document.createElement('hr'); var h = document.createElement('header'); var t = document.createElement('h1'); var c = document.createTextNode(ctt.Title); + var d = document.createElement('p'); + d.appendChild(document.createTextNode(ctt.desp)); + d.id = 'header-desp'; + var ti = document.createElement('p'); + ti.appendChild(document.createTextNode(ctt.edit || ctt.create)); + ti.id = 'header-ti'; + var tag = bloggie.custom.command.tagGroupMaker(ctt.tags, true); + tag.id = 'header-tag' t.appendChild(c); h.appendChild(t); - h.appendChild(r); + h.style.backgroundColor = ctt.color || '#036ac4'; + h.setAttribute('data-icon', ctt.icon || ''); + h.appendChild(d); + h.appendChild(ti); + h.appendChild(tag); return h; } }; @@ -32,21 +43,24 @@ bloggie.custom.command.loadcontentafterarticle = (ctt) => { var f = document.createElement('footer'); if (ctt.Comment) { var h = document.createElement('hr'); - var y = new Date().getFullYear(); - var p = document.createElement('p'); - p.appendChild(document.createTextNode(`© 2023-`+y+` DaleZ`)); f.appendChild(h); - f.appendChild(p); - f.innerHTML += `
本站文章除其作者特殊声明外,一律采用CC BY-NC-SA 4.0许可协议进行授权,进行转载或二次创作时务必以相同协议进行共享,严禁用于商业用途。
`; + var y = new Date().getFullYear(); + f.innerHTML += `© 2023-${y} DaleZ
本站文章除其作者特殊声明外,一律采用CC BY-NC-SA 4.0许可协议进行授权,进行转载或二次创作时务必以相同协议进行共享,严禁用于商业用途。
本站文章除其作者特殊声明外,一律采用CC BY-NC-SA 4.0许可协议进行授权,进行转载或二次创作时务必以相同协议进行共享,严禁用于商业用途。
`; + var y = new Date().getFullYear(); + f.innerHTML += `© 2023-${y} DaleZ
本站文章除其作者特殊声明外,一律采用CC BY-NC-SA 4.0许可协议进行授权,进行转载或二次创作时务必以相同协议进行共享,严禁用于商业用途。
更新已可用。