Skip to content

Commit

Permalink
feat: improve tags in title
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed May 5, 2022
1 parent 1d4828f commit bba6e5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
35 changes: 35 additions & 0 deletions assets/js/SeoHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

import { capitalize } from "lodash-es";

export class SeoHelper {

static tagArrayToTitle(tags) {

if (!tags) {
return undefined;
}

const CAPITALIZED_TAGS = tags
.map(tag => capitalize(tag))
.join(", ");

return this.normalizeStringForTitle(CAPITALIZED_TAGS);
}

static normalizeStringForTitle(title) {
title = title.trim()

// Replace underscores with spaces
title = title.replace(/_/g, ' ')

// Replace parentheses with empty string
title = title.replace(/\(/g, '')
title = title.replace(/\)/g, '')

// Replace colon with empty string
title = title.replace(/:/g, '')

return title
}
}
7 changes: 3 additions & 4 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@

<script>
import { mapActions, mapGetters } from 'vuex'
import { capitalize } from 'lodash-es'
// Mixins
import FetchPostsMixin from '~/components/pages/posts/post/FetchPostsMixin.js'
import { SeoHelper } from "~/assets/js/SeoHelper";
export default {
mixins: [FetchPostsMixin],
Expand All @@ -85,9 +85,8 @@ export default {
],
}
let tags = this.getTags.join(', ')
tags = capitalize(tags)
// Join array of tags into a comma separated string
const tags = SeoHelper.tagArrayToTitle(this.getTags)
if (tags) {
head.title = tags + ' Hentai Porn'
Expand Down

0 comments on commit bba6e5d

Please sign in to comment.