mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
Update to auto generate meta description based on content in publish note and slide
This commit is contained in:
parent
8c10c393ce
commit
71a356552f
2 changed files with 17 additions and 7 deletions
|
@ -260,6 +260,9 @@ module.exports = function (sequelize, DataTypes) {
|
|||
if (!title) title = "Untitled";
|
||||
return title;
|
||||
},
|
||||
generateDescription: function (markdown) {
|
||||
return markdown.substr(0, 100).replace(/(?:\r\n|\r|\n)/g, ' ');
|
||||
},
|
||||
decodeTitle: function (title) {
|
||||
var decodedTitle = LZString.decompressFromBase64(title);
|
||||
if (decodedTitle) title = decodedTitle;
|
||||
|
|
|
@ -178,8 +178,11 @@ function showPublishNote(req, res, next) {
|
|||
}
|
||||
var body = LZString.decompressFromBase64(note.content);
|
||||
var meta = null;
|
||||
var markdown = null;
|
||||
try {
|
||||
meta = models.Note.parseMeta(metaMarked(body).meta);
|
||||
var obj = metaMarked(body);
|
||||
markdown = obj.markdown;
|
||||
meta = models.Note.parseMeta(obj.meta);
|
||||
} catch(err) {
|
||||
//na
|
||||
}
|
||||
|
@ -191,7 +194,7 @@ function showPublishNote(req, res, next) {
|
|||
var origin = config.serverurl;
|
||||
var data = {
|
||||
title: title,
|
||||
description: meta.description,
|
||||
description: meta.description || markdown ? models.Note.generateDescription(markdown) : null,
|
||||
viewcount: note.viewcount,
|
||||
createtime: createtime,
|
||||
updatetime: updatetime,
|
||||
|
@ -249,8 +252,11 @@ function actionDownload(req, res, note) {
|
|||
function actionInfo(req, res, note) {
|
||||
var body = LZString.decompressFromBase64(note.content);
|
||||
var meta = null;
|
||||
var markdown = null;
|
||||
try {
|
||||
meta = models.Note.parseMeta(metaMarked(body).meta);
|
||||
var obj = metaMarked(body);
|
||||
markdown = obj.markdown;
|
||||
meta = models.Note.parseMeta(obj.meta);
|
||||
} catch(err) {
|
||||
//na
|
||||
}
|
||||
|
@ -260,7 +266,7 @@ function actionInfo(req, res, note) {
|
|||
var title = models.Note.decodeTitle(note.title);
|
||||
var data = {
|
||||
title: meta.title || title,
|
||||
description: meta.description,
|
||||
description: meta.description || markdown ? models.Note.generateDescription(markdown) : null,
|
||||
viewcount: note.viewcount,
|
||||
createtime: createtime,
|
||||
updatetime: updatetime
|
||||
|
@ -560,9 +566,10 @@ function showPublishSlide(req, res, next) {
|
|||
}
|
||||
var body = LZString.decompressFromBase64(note.content);
|
||||
var meta = null;
|
||||
var markdown = null;
|
||||
try {
|
||||
var obj = metaMarked(body);
|
||||
body = obj.markdown;
|
||||
markdown = obj.markdown;
|
||||
meta = models.Note.parseMeta(obj.meta);
|
||||
} catch(err) {
|
||||
//na
|
||||
|
@ -575,12 +582,12 @@ function showPublishSlide(req, res, next) {
|
|||
var origin = config.serverurl;
|
||||
var data = {
|
||||
title: title,
|
||||
description: meta.description,
|
||||
description: meta.description || markdown ? models.Note.generateDescription(markdown) : null,
|
||||
viewcount: note.viewcount,
|
||||
createtime: createtime,
|
||||
updatetime: updatetime,
|
||||
url: origin,
|
||||
body: body,
|
||||
body: markdown,
|
||||
meta: JSON.stringify(obj.meta || {}),
|
||||
useCDN: config.usecdn,
|
||||
owner: note.owner ? note.owner.id : null,
|
||||
|
|
Loading…
Reference in a new issue