Make pages.meet post expand post "tags" into the HTML

This commit is contained in:
Niko 2022-02-17 21:56:23 +01:00
parent c1ac8d5673
commit 5c5c5091b4
3 changed files with 53 additions and 2 deletions

View File

@ -18,6 +18,16 @@ module.exports = {
.toArray()
for (var i = 0; i < notes.length; i++) {
const note = notes[i]
var tags = []
if (note.tag !== undefined) {
for (var j = 0; j < note.tag.length; j++) {
tags.push({
type: note.tag[j].type,
href: utils.firstIfArray(note.tag[j].href),
name: utils.firstIfArray(note.tag[j].name),
})
}
}
results.push({
_id: note._id,
text: utils.firstIfArray(note.content),
@ -25,6 +35,7 @@ module.exports = {
account: await api.accounts.getAccount(
utils.firstIfArray(note.attributedTo)
),
tags,
})
}
return res.json(results)

View File

@ -108,7 +108,47 @@ app.storage = {
localStorage['fedilove'] = JSON.stringify(js);
return true;
},
};
}
app.post = {
prepare4html: function(value, tags) {
tags = tags || [];
console.log(value);
value = value.replaceAll('</a>', '</a> ')
.replaceAll(/\s+/g, ' ');
value = value.replaceAll('</p>', '{:br:}{:br:}');
value = html2text(value).replaceAll(/\s+/g, ' ')+' ';
var replaceAfter = [];
for (var i = 0; i < tags.length; i++) {
if (tags[i].type.toLowerCase().trim() === 'mention') {
var acct = tags[i].name;
var href = tags[i].href;
if (acct === undefined || href === undefined)
continue;
if (!acct.match(/^@[^@]+@[^@]+$/))
continue;
acct = acct.trim().substr(1);
href = href.trim();
const ps = acct.split('@');
const link = '<a class="mention" href="'+htmlescape(href)+'">@'+
htmlescape(acct) + '</a>';
replaceAfter.push(['@'+ps[0], link]);
replaceAfter.push(['@'+acct, link]);
}
}
value = html2text(value);
for (var i = 0; i < replaceAfter.length; i++) {
const it = replaceAfter[i];
value = value.replaceAll(it[0], it[1]);
}
value = value.replaceAll('{:br:}', '<br>');
value = value.trim().replaceAll(/<br><br>$/g, '');
console.log(value);
console.log(tags);
console.log('----');
return value;
},
}
app.overlay = {
hideAll: function() {

View File

@ -56,7 +56,7 @@ app.pages.meet = {
var tpl = app.template.fill(item, app.template.get('meet.item'),
function (k,v) {
if (k === 'text') return html2text(v);
if (k === 'text') return app.post.prepare4html(item.text, item.tags);
if (k === 'account.name') return capitalize(v);
if (k === 'date') return dayjs(v).fromNow(true);
});