mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-26 23:43:16 +00:00
Merge pull request #191 from ErikMichelson/feature/ogmetadata
Add customizable opengraph metadata for notes (see #40)
This commit is contained in:
commit
cd34a8c702
6 changed files with 55 additions and 2 deletions
|
@ -409,9 +409,18 @@ module.exports = function (sequelize, DataTypes) {
|
|||
if (meta.GA && (typeof meta.GA === 'string' || typeof meta.GA === 'number')) { _meta.GA = meta.GA }
|
||||
if (meta.disqus && (typeof meta.disqus === 'string' || typeof meta.disqus === 'number')) { _meta.disqus = meta.disqus }
|
||||
if (meta.slideOptions && (typeof meta.slideOptions === 'object')) { _meta.slideOptions = meta.slideOptions }
|
||||
if (meta.opengraph && (typeof meta.opengraph === 'object')) { _meta.opengraph = meta.opengraph }
|
||||
}
|
||||
return _meta
|
||||
}
|
||||
Note.parseOpengraph = function (meta, title) {
|
||||
var _ogdata = {}
|
||||
if (meta.opengraph) { _ogdata = meta.opengraph }
|
||||
if (!(_ogdata.title && (typeof _ogdata.title === 'string' || typeof _ogdata.title === 'number'))) { _ogdata.title = title }
|
||||
if (!(_ogdata.description && (typeof _ogdata.description === 'string' || typeof _ogdata.description === 'number'))) { _ogdata.description = meta.description || '' }
|
||||
if (!(_ogdata.type && (typeof _ogdata.type === 'string'))) { _ogdata.type = 'website' }
|
||||
return _ogdata
|
||||
}
|
||||
Note.updateAuthorshipByOperation = function (operation, userId, authorships) {
|
||||
var index = 0
|
||||
var timestamp = Date.now()
|
||||
|
|
|
@ -98,12 +98,14 @@ function responseCodiMD (res, note) {
|
|||
var meta = models.Note.parseMeta(extracted.meta)
|
||||
var title = models.Note.decodeTitle(note.title)
|
||||
title = models.Note.generateWebTitle(meta.title || title)
|
||||
var opengraph = models.Note.parseOpengraph(meta, title)
|
||||
res.set({
|
||||
'Cache-Control': 'private', // only cache by client
|
||||
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
||||
})
|
||||
res.render('codimd.ejs', {
|
||||
title: title
|
||||
title: title,
|
||||
opengraph: opengraph
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -217,6 +219,7 @@ function showPublishNote (req, res, next) {
|
|||
var updatetime = note.lastchangeAt
|
||||
var title = models.Note.decodeTitle(note.title)
|
||||
title = models.Note.generateWebTitle(meta.title || title)
|
||||
var ogdata = models.Note.parseOpengraph(meta, title)
|
||||
var data = {
|
||||
title: title,
|
||||
description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null),
|
||||
|
@ -232,7 +235,8 @@ function showPublishNote (req, res, next) {
|
|||
GA: meta.GA,
|
||||
disqus: meta.disqus,
|
||||
cspNonce: res.locals.nonce,
|
||||
dnt: req.headers.dnt
|
||||
dnt: req.headers.dnt,
|
||||
opengraph: ogdata
|
||||
}
|
||||
return renderPublish(data, res)
|
||||
}).catch(function (err) {
|
||||
|
|
|
@ -159,3 +159,20 @@ slideOptions:
|
|||
transition: fade
|
||||
theme: white
|
||||
```
|
||||
|
||||
opengraph
|
||||
---
|
||||
This option allows you to override the default generated opengraph metadata.
|
||||
See the [OpenGraph protocol documentation](https://ogp.me) for more information.
|
||||
|
||||
**Notice: always use two spaces as indention in YAML metadata!**
|
||||
|
||||
> default: not set (uses auto-generated metadata)
|
||||
|
||||
**Example**
|
||||
```yml
|
||||
opengraph:
|
||||
title: Special title for OpenGraph protocol
|
||||
image: https://dummyimage.com/600x600/000/fff
|
||||
image:type: image/png
|
||||
```
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<% for (var og in opengraph) { %>
|
||||
<% if (opengraph.hasOwnProperty(og) && opengraph[og].trim() !== '') { %>
|
||||
<meta property="og:<%- og %>" content="<%- opengraph[og] %>">
|
||||
<% }} if (!opengraph.hasOwnProperty('image')) { %>
|
||||
<meta property="og:image" content="<%- serverURL %>/codimd-icon-1024.png">
|
||||
<meta property="og:image:alt" content="CodiMD logo">
|
||||
<meta property="og:image:type" content="image/png">
|
||||
<% } %>
|
||||
<title><%= title %></title>
|
||||
<link rel="icon" type="image/png" href="<%- serverURL %>/favicon.png">
|
||||
<link rel="apple-touch-icon" href="<%- serverURL %>/apple-touch-icon.png">
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="description" content="<%= __('Best way to write and share your knowledge in markdown.') %>">
|
||||
<meta name="keywords" content="Collaborative, Markdown, Notes">
|
||||
<meta property="og:title" content="CodiMD - <%= __('Collaborative markdown notes') %>">
|
||||
<meta property="og:description" content="<%= __('Best way to write and share your knowledge in markdown.') %>">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="<%- serverURL %>">
|
||||
<meta property="og:image" content="<%- serverURL %>/codimd-icon-1024.png">
|
||||
<meta property="og:image:alt" content="CodiMD logo">
|
||||
<meta property="og:image:type" content="image/png">
|
||||
<title>CodiMD - <%= __('Collaborative markdown notes') %></title>
|
||||
<link rel="icon" type="image/png" href="<%- serverURL %>/favicon.png">
|
||||
<link rel="apple-touch-icon" href="<%- serverURL %>/apple-touch-icon.png">
|
||||
|
|
|
@ -14,6 +14,14 @@
|
|||
<% if(typeof description !== 'undefined' && description) { %>
|
||||
<meta name="description" content="<%= description %>">
|
||||
<% } %>
|
||||
<% for (var og in opengraph) { %>
|
||||
<% if (opengraph.hasOwnProperty(og) && opengraph[og].trim() !== '') { %>
|
||||
<meta property="og:<%= og %>" content="<%= opengraph[og] %>">
|
||||
<% }} if (!opengraph.hasOwnProperty('image')) { %>
|
||||
<meta property="og:image" content="<%- serverURL %>/codimd-icon-1024.png">
|
||||
<meta property="og:image:alt" content="CodiMD logo">
|
||||
<meta property="og:image:type" content="image/png">
|
||||
<% } %>
|
||||
<title><%= title %></title>
|
||||
<link rel="icon" type="image/png" href="<%- serverURL %>/favicon.png">
|
||||
<link rel="apple-touch-icon" href="<%- serverURL %>/apple-touch-icon.png">
|
||||
|
|
Loading…
Reference in a new issue