breaking change in configuration
This commit is contained in:
parent
f1b32bd47e
commit
0ca65fbca5
20 changed files with 373 additions and 361 deletions
|
@ -1,57 +0,0 @@
|
|||
const dom = document.getElementById('friends')
|
||||
|
||||
const topk = '{{.Site.Params.friends.topk}}'
|
||||
const raw = '{{.Site.Params.friends.feeds}}'
|
||||
|
||||
const feeds = raw.replace(/^\[|\]$/g, '').split(' ')
|
||||
|
||||
feeds.forEach(v => fetch(v).then(r => r.text()).then(r => rss(r)))
|
||||
|
||||
/**
|
||||
* @param {string} xml
|
||||
*/
|
||||
function rss(xml) {
|
||||
xml = xml.trim().replace(/\n/g, '')
|
||||
const g = xml.matchAll(/<(item|entry)>.*?<\/(item|entry)>/g)
|
||||
let n = +topk || 2;
|
||||
while (n) {
|
||||
const next = g.next()
|
||||
if (next.done) {
|
||||
break
|
||||
}
|
||||
|
||||
// title
|
||||
const title = next.value[0].match(/(?<=<title>).*(?=<\/title>)/)[0]
|
||||
|
||||
// link
|
||||
const link = next.value[0].match(/(?<=<(link|id)>).*(?=<\/(link|id)>)/)[0]
|
||||
|
||||
// date
|
||||
const date = next.value[0].match(/(?<=<(pubDate|updated)>).*(?=<\/(pubDate|updated)>)/)[0]
|
||||
|
||||
// innsert dom
|
||||
const div = document.createElement('div')
|
||||
div.className = 'flex justify-between'
|
||||
div.innerHTML = template(link, title, date)
|
||||
dom.appendChild(div)
|
||||
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} date
|
||||
*/
|
||||
function format(date) {
|
||||
const d = new Date(date)
|
||||
return d.toDateString()
|
||||
}
|
||||
|
||||
|
||||
function template() {
|
||||
const a = arguments
|
||||
return `
|
||||
<a href=${a[0]}>${a[1]}</a>
|
||||
<div>${format(a[2])}</div>
|
||||
`.trim()
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import "./theme";
|
||||
import "./style";
|
||||
import "./selectable";
|
||||
import "./friends";
|
|
@ -1,9 +1,11 @@
|
|||
// fix style of checkboxes in posts.
|
||||
// fix style of checked/unchecked list items
|
||||
document.querySelectorAll('.md ul').forEach(v => {
|
||||
if (/<li><input .+>.+<\/li>/.test(v.innerHTML)) {
|
||||
console.log(v);
|
||||
v.classList.add('ul-checkbox');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// // use custom font family
|
||||
// document.querySelector('body').style.setProperty('--global-font-family', '{{ .Site.Params.globalFontFamily }}');
|
Loading…
Add table
Add a link
Reference in a new issue