From 00b1447600a73800f2cd9d000b2da4dece1dbb42 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Thu, 23 Dec 2021 22:02:27 +0100 Subject: [PATCH] [head] add missing descriptions --- routes/blogEntry.vue | 1 + routes/census.vue | 1 + routes/profile.vue | 1 + routes/pronoun.vue | 5 +++++ routes/sources.vue | 1 + routes/team.vue | 1 + src/helpers.js | 3 +++ src/parseMarkdown.js | 8 +++++++- 8 files changed, 20 insertions(+), 1 deletion(-) diff --git a/routes/blogEntry.vue b/routes/blogEntry.vue index 0c3b6866b..864054be0 100644 --- a/routes/blogEntry.vue +++ b/routes/blogEntry.vue @@ -34,6 +34,7 @@ head() { return head({ title: this.title, + description: this.intro, banner: this.img, }); }, diff --git a/routes/census.vue b/routes/census.vue index 623898405..1bc6d9592 100644 --- a/routes/census.vue +++ b/routes/census.vue @@ -267,6 +267,7 @@ head() { return head({ title: this.$t('census.headerLong'), + description: this.$t('census.description')[0], }); }, }; diff --git a/routes/profile.vue b/routes/profile.vue index a53703756..b9c92a544 100644 --- a/routes/profile.vue +++ b/routes/profile.vue @@ -221,6 +221,7 @@ head() { return head({ title: `@${this.username}`, + description: this.profile ? this.profile.description : null, banner: `api/banner/@${this.username}.png`, }); }, diff --git a/routes/pronoun.vue b/routes/pronoun.vue index 2ea64d8f5..719229a03 100644 --- a/routes/pronoun.vue +++ b/routes/pronoun.vue @@ -139,6 +139,11 @@ head() { return this.selectedPronoun ? head({ title: `${this.$t('pronouns.intro')}: ${this.selectedPronoun.name(this.glue)}`, + description: [ + this.$t('pronouns.examples', {}, false), + this.$t('pronouns.grammarTable', {}, false), + this.$t('sources.headerLong', {}, false), + ].filter(x => !!x).join(', '), banner: `api/banner${this.$route.path.replace(/\/$/, '')}.png`, }) : {}; }, diff --git a/routes/sources.vue b/routes/sources.vue index f6f567715..9e2e68c41 100644 --- a/routes/sources.vue +++ b/routes/sources.vue @@ -175,6 +175,7 @@ head() { return head({ title: this.$t('sources.headerLonger'), + description: this.$t('sources.subheader'), }); }, methods: { diff --git a/routes/team.vue b/routes/team.vue index c65079dbd..a115b75d1 100644 --- a/routes/team.vue +++ b/routes/team.vue @@ -127,6 +127,7 @@ head() { return head({ title: this.$t('contact.team.name'), + description: this.$t('contact.team.description'), }); }, async asyncData({app}) { diff --git a/src/helpers.js b/src/helpers.js index 9f217f02c..d67d06cbe 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -32,6 +32,7 @@ export const head = ({title, description, banner}) => { if (description) { description = clearLinkedText(description); + description = description.split(' ').slice(0, 24).join(' ') + '…'; meta.meta.push({ hid: 'description', name: 'description', content: description }); meta.meta.push({ hid: 'og:description', property: 'og:description', content: description }); meta.meta.push({ hid: 'twitter:description', property: 'twitter:description', content: description }); @@ -207,6 +208,8 @@ export const clearLinkedText = (text, quotes = true) => { text = text.replace(/[„”"']/g, ''); } + text = text.replace(/\s+/g, ' '); + return text; } diff --git a/src/parseMarkdown.js b/src/parseMarkdown.js index 5f2d6a152..441d10ec4 100644 --- a/src/parseMarkdown.js +++ b/src/parseMarkdown.js @@ -13,11 +13,17 @@ export default async function parseMarkdown(markdown) { const title = titleMatch ? titleMatch[1] : null; const imgMatch = content.match(']*>'); const img = imgMatch ? imgMatch[1] : null; + let intro = []; + for (let introMatch of content.matchAll(']*>([^<]+)

')) { + const p = introMatch[1].replace(/(<([^>]+)>)/ig, '').replace(/\s+/g, ' '); + intro = [...intro, ...p.split(' ')]; + } return { - content, title, img, + intro: intro.length ? intro.slice(0, 24).join(' ') : null, + content, } } catch { return {