Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SEO properties to collection pages #3999

Merged
merged 7 commits into from
Apr 3, 2024
Merged

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Apr 1, 2024

Fixes

Fixes #3917 by @obulat

Description

This PR adds the titles to the collection pages (title used at the top of a page and og:title that's used when sharing the page). The following titles were used, suggested by @zackkrida :

- {tag} {mediaType} | Openverse: "Dog images", "Field-recording audio tracks"
- {creatorName} | Openverse: "zackkrida", "sarayourfriend" [Deliberately non-specific in the future event of multi-media type creators]
- {provider} {mediaType} | Openverse: "Flickr images", "ccMixter audio tracks"

I also added the comments to i18n strings to give some context for translators.

Testing Instructions

Run the app locally using just frontend/run dev
Switch the additional_search_views flag on on http://localhost8443/preferences
Check the <head> of the collection pages. It should have correct title and og:title set. This is also tested in the playwright seo test.

If you have any suggestions for wording of the titles or the translator comments, please add them here, too.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Olga Bulat <obulat@gmail.com>
@obulat obulat requested a review from a team as a code owner April 1, 2024 15:52
@obulat obulat self-assigned this Apr 1, 2024
@obulat obulat added the 🧱 stack: frontend Related to the Nuxt frontend label Apr 1, 2024
@openverse-bot openverse-bot added 🟧 priority: high Stalls work on the project or its dependents 🌟 goal: addition Addition of new feature 💻 aspect: code Concerns the software code in the repository labels Apr 1, 2024
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked that the titles show up in the head element, looks good besides one note!

frontend/src/locales/scripts/en.json5 Outdated Show resolved Hide resolved
Co-authored-by: Madison Swain-Bowden <bowdenm@spu.edu>
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for just a couple specific things, with a few others left in the air open for you to decide. The specific changes are: clarify the purpose of the string and simplify the translator comment, with the goal of making it clear that it's a browser page title and needs to be SEO friendly; and interpolate {openverse} the way we do in other places.

POT generation needs to be checked to make sure it doesn't get confused about the | character.

Comment on lines 1056 to 1082
/**
* {tag} will be a dynamic value such as "cat". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Audio tracks with the tag {tag}".
*/
audio: "{tag} audio tracks | Openverse",

/**
* {tag} will be a dynamic value such as "cat". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Images with the tag {tag}".
*/
image: "{tag} images | Openverse",
},
source: {
/**
* {source} will be a dynamic value such as "Wikimedia". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Audio tracks from {source}".
*/
audio: "{source} audio tracks | Openverse",
/**
* {source} will be a dynamic value such as "Wikimedia". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Images from {source}".
*/
image: "{source} images | Openverse",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth mentioning in these comments that they are used as browser page titles in particular. That might help clarify a preference for a succinct string rather than something fully descriptive or strictly gramatically correct, rather, it needs to be SEO friendly (I imagine length is a factor here). We can probably leave out the "You can change the sentence...", so that it's clear it does not need to be a complete sentence, but rather clarifying that it must be an SEO friendly phrase?

We normally interpolate Openverse as a variable. Any reason not to do that here?

Also, in Glotpress the curly praces are replaced with ###, so it might be better to just quote "tag" (etc.) than reference it with the curly braces, which only make sense in the context of the original string.

Just suggestions below, nothing blocking here other than the Openverse intepolation if we should keep it.

Also: will the POT transformer get confused about the | in the string and think it's a plural form string, by any chance? Maybe that also needs to be interpolated or included in {openverse} as " | Openverse with the leading space? It could be better to have the strings here only be the titles, leaving out the | Openverse part altogether, and then interpolating the translated result into a plain template string, like `${i18n.t("pageTitle.tag.image", { tag })} | Openverse`? That way there is no chance the POT transformer gets confused about whether these are plural form strings and translators don't need to worry about or focus on spacing of the pipe and Openverse. If we need to use a template for the whole thing for e.g., RTL, then we can use two separate templates and interpolate them into each other, with a generic template for the page-title form: "{pageTitle} {pipe} {openverse}" for example. And then a note to the translator explaining what each variable will be and to reorder it as needed with Openverse always separated from the actual title by the pipe.

Suggested change
/**
* {tag} will be a dynamic value such as "cat". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Audio tracks with the tag {tag}".
*/
audio: "{tag} audio tracks | Openverse",
/**
* {tag} will be a dynamic value such as "cat". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Images with the tag {tag}".
*/
image: "{tag} images | Openverse",
},
source: {
/**
* {source} will be a dynamic value such as "Wikimedia". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Audio tracks from {source}".
*/
audio: "{source} audio tracks | Openverse",
/**
* {source} will be a dynamic value such as "Wikimedia". We cannot change its case or form.
* You can change the sentence to add more context and make the sentence
* grammatically correct, for instance, to "Images from {source}".
*/
image: "{source} images | Openverse",
/**
* "tag" will be a dynamic value such as "cat". We cannot change its case or form.
* Used as browser page title and must be SEO friendly
*/
audio: "{tag} audio tracks | {openverse}",
/**
* "tag" will be a dynamic value such as "cat". We cannot change its case or form.
* Used as browser page title and must be SEO friendly
*/
image: "{tag} images | {openverse}",
},
source: {
/**
* "source" will be a dynamic value such as "Wikimedia Commons". We cannot change its case or form.
* Used as browser page title and must be SEO friendly
*/
audio: "{source} audio tracks | {openverse}",
/**
* "source" will be a dynamic value such as "Wikimedia Commons". We cannot change its case or form.
* Used as browser page title and must be SEO friendly
*/
image: "{source} images | {openverse}",

const providerStore = useProviderStore()

if (collectionParams.value?.collection === "creator") {
return `${collectionParams.value.creator} | Openverse`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, in RTL this might also need to be changed? I'm not sure how a browser configured for RTL and with dir="rtl" set on a page will interpret a browser title that isn't formatted RTL? Maybe page titles cannot be RTL at all, do you know?

use-collection-meta.ts is refactored to add a static " | Openverse" string to the title to prevent confusion with pluralized i18n strings

Signed-off-by: Olga Bulat <obulat@gmail.com>
Add suggestions from code review

Update the strings: add comment that the phrases will be used for page titles
Signed-off-by: Olga Bulat <obulat@gmail.com>
@obulat
Copy link
Contributor Author

obulat commented Apr 2, 2024

Requesting changes for just a couple specific things, with a few others left in the air open for you to decide. The specific changes are: clarify the purpose of the string and simplify the translator comment, with the goal of making it clear that it's a browser page title and needs to be SEO friendly; and interpolate {openverse} the way we do in other places.

POT generation needs to be checked to make sure it doesn't get confused about the | character.

Thank you for your review, these points are really important.

For other page titles, we use i18n to translate the title itself, and add the | Openverse string to it, like here:

title: `${i18n.t("sensitive.title")} | Openverse`,

I've refactored the code to do the same here. This way, we don't have to interpolate openverse, and the | pipe character will not break anything.


I added the notes that the phrases will be used as page title and that they must be SEO-friendly. I didn't remove the comment about a different sentence, though, because we don't want the title to be ungrammatical simply to be SEO-friendly. I have seen the translations done that way in other apps, and I am strongly against doing this in Openverse.

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, this LGTM!

const pageTitle = computed(() => {
// The default page title. It should be overwritten by the specific collection type.
let title: string | TranslateResult =
"Openly Licensed Images, Audio and More"
Copy link
Collaborator

@sarayourfriend sarayourfriend Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used as a fallback to appease TypeScript? If so, we can use a return in each case instead of assigning to a variable. Otherwise, I suppose this should be translated too, in case for some reason it is used? Not-blocking, but definitely needs an issue to fast-follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to not use string | TranslateResult.

I tried using the switch/case, but because the function is inside a computed, it causes an Expected to return a value in computed function vue/return-in-computed-property linting error, even though all of the collectionParams.collection options are exhausted. That's why I used a redundant if cause.

Signed-off-by: Olga Bulat <obulat@gmail.com>
Signed-off-by: Olga Bulat <obulat@gmail.com>
Signed-off-by: Olga Bulat <obulat@gmail.com>
@obulat obulat merged commit 213c886 into main Apr 3, 2024
40 checks passed
@obulat obulat deleted the add/collection_seo_properties branch April 3, 2024 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🌟 goal: addition Addition of new feature 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add SEO properties to the collection pages
4 participants