Skip to content

Commit

Permalink
fix(seo): add negative tags in title
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Jun 8, 2023
1 parent 0d41668 commit 797214d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
26 changes: 14 additions & 12 deletions assets/js/SeoHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ export function tagArrayToTitle(tags: Tag[]) {
return null
}

return (
tags
.map((tag) => tag.name)
// .map((tag) => capitalize(tag))
.map((tag) => normalizeStringForTitle(tag))
.join(', ')
)
const cleanedTags = tags
//
.map((tag) => tag.name)
//
.map((tag) => normalizeStringForTitle(tag))

const tagsThatStartWithNothing = cleanedTags.filter((tag) => !tag.startsWith('-'))

const tagsThatStartWithMinus = cleanedTags
//
.filter((tag) => tag.startsWith('-'))
.map((tag) => tag.replace('-', ''))

return `${tagsThatStartWithNothing.join(', ')}, and without ${tagsThatStartWithMinus.join(', ')}`
}

export function normalizeStringForTitle(string: string) {
Expand All @@ -21,11 +28,6 @@ export function normalizeStringForTitle(string: string) {

string = string.trim()

// Delete negative tag
if (string.startsWith('-')) {
return null
}

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

Expand Down
8 changes: 2 additions & 6 deletions pages/posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,7 @@
let title = ''
if (selectedTags.value.length > 0) {
title += ` Tagged with ` + tagArrayToTitle(selectedTags.value.slice(0, 2))
if (selectedTags.value.length > 2) {
title += ' and more…'
}
title += ` Tagged with ` + tagArrayToTitle(selectedTags.value)
}
// TODO: Filters
Expand Down Expand Up @@ -378,7 +374,7 @@

<h1 class="text-base font-medium">Posts</h1>

<h2 class="mb-3 text-sm">
<h2 class="mb-3 truncate text-sm">
<!-- TODO: Make tags and filters clickable so they open search menu -->
{{ bodyTitle }}
</h2>
Expand Down

0 comments on commit 797214d

Please sign in to comment.