#57 meta helper

This commit is contained in:
Avris 2020-09-23 21:29:55 +02:00
parent f38222512f
commit 3f3dbadb00
6 changed files with 50 additions and 65 deletions

View File

@ -120,6 +120,7 @@
<script>
import { examples, templates, getSources } from "~/src/data";
import { buildTemplate } from "../src/buildTemplate";
import { head } from "../src/helpers";
export default {
data() {
@ -138,23 +139,10 @@
}
},
head() {
if (!this.selectedTemplate) {
return {};
}
const title = 'Moje zaimki to: ' + this.selectedTemplate.name();
const banner = `${process.env.baseUrl}/banner${this.$route.path.replace(/\/$/, '')}.png`;
return {
title: title,
meta: [
{ hid: 'og:title', property: 'og:title', content: title },
{ hid: 'twitter:title', property: 'twitter:title', content: title },
{ hid: 'og:logo', property: 'og:logo', content: banner },
{ hid: 'twitter:image', property: 'twitter:image', content: banner },
],
}
return this.selectedTemplate ? head({
title: 'Moje zaimki to: ' + this.selectedTemplate.name(),
banner: `banner${this.$route.path.replace(/\/$/, '')}.png`,
}) : {};
},
computed: {
sources() {

View File

@ -54,6 +54,7 @@
<script>
import { examples, templates } from "~/src/data";
import { head } from "../src/helpers";
export default {
data() {
@ -62,19 +63,10 @@
}
},
head() {
const title = 'Moje zaimki to: dowolne • Zaimki.pl';
const banner = `${process.env.baseUrl}/banner/dowolne.png`;
return {
title: title,
meta: [
{ hid: 'og:title', property: 'og:title', content: title },
{ hid: 'twitter:title', property: 'twitter:title', content: title },
{ hid: 'og:logo', property: 'og:logo', content: banner },
{ hid: 'twitter:image', property: 'twitter:image', content: banner },
],
}
return head({
title: 'Moje zaimki to: dowolne',
banner: 'banner/dowolne.png',
});
},
methods: {
randomTemplate() {

View File

@ -12,17 +12,13 @@
</template>
<script>
import { head } from "../src/helpers";
export default {
head() {
const title = 'Kontakt • Zaimki.pl';
return {
title: title,
meta: [
{ hid: 'og:title', property: 'og:title', content: title },
{ hid: 'twitter:title', property: 'twitter:title', content: title },
],
}
return head({
title: 'Kontakt',
});
},
}
</script>

View File

@ -125,6 +125,7 @@
<script>
import { templates, sources, sourcesForMultipleForms, templateLibrary } from '../src/data'
import { Source } from "../src/classes";
import { head } from "../src/helpers";
export default {
data() {
@ -146,14 +147,9 @@
}
},
head() {
const title = 'Niebinarna polszczyzna w tekstach kultury • Zaimki.pl';
return {
title: title,
meta: [
{ hid: 'og:title', property: 'og:title', content: title },
{ hid: 'twitter:title', property: 'twitter:title', content: title },
],
}
return head({
title: 'Niebinarna polszczyzna w tekstach kultury',
});
},
computed: {
otherSources() {

View File

@ -245,6 +245,7 @@
<script>
import { Noun } from "~/src/classes";
import { buildDict } from "../src/helpers";
import { head } from "../src/helpers";
export default {
data() {
@ -335,24 +336,11 @@
}
},
head() {
const title = 'Słownik neutratywów • Zaimki.pl';
const description = 'Feminatywy feminatywami, ale prawdziwe wyzwanie to tworzenie neutratywów! Przedstawiamy tworzony przez społeczność słownik rzeczowników z wyszczególnieniem ich formy męskiej, żeńskiej i neutralnej.';
const banner = `${process.env.baseUrl}/bannerNouns.png`;
return {
title: title,
meta: [
{ hid: 'og:title', property: 'og:title', content: title },
{ hid: 'twitter:title', property: 'twitter:title', content: title },
{ hid: 'description', name: 'description', content: description },
{ hid: 'og:description', property: 'og:description', content: description },
{ hid: 'twitter:description', property: 'twitter:description', content: description },
{ hid: 'og:logo', property: 'og:logo', content: banner },
{ hid: 'twitter:image', property: 'twitter:image', content: banner },
],
}
return head({
title: 'Słownik neutratywów',
description: 'Feminatywy feminatywami, ale prawdziwe wyzwanie to tworzenie neutratywów! Przedstawiamy tworzony przez społeczność słownik rzeczowników z wyszczególnieniem ich formy męskiej, żeńskiej i neutralnej.',
banner: 'bannerNouns.png',
});
},
}
</script>

View File

@ -13,3 +13,28 @@ export const buildList = (fn, ...args) => {
}
return list;
}
export const head = ({title, description, banner}) => {
const meta = { meta: [] };
if (title) {
title += ' • Zaimki.pl';
meta.title = title;
meta.meta.push({ hid: 'og:title', property: 'og:title', content: title });
meta.meta.push({ hid: 'twitter:title', property: 'twitter:title', content: title });
}
if (description) {
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 });
}
if (banner) {
banner = process.env.baseUrl + '/' + banner;
meta.meta.push({ hid: 'og:logo', property: 'og:logo', content: banner });
meta.meta.push({ hid: 'twitter:image', property: 'twitter:image', content: banner });
}
return meta;
}