NCEAS / metacatui

MetacatUI: A client-side web interface for DataONE data repositories
https://nceas.github.io/metacatui
Apache License 2.0
42 stars 28 forks source link

Update page titles dynamically #1723

Open amoeba opened 3 years ago

amoeba commented 3 years ago

@BrennieDev just brought this up on Slack and Erin McLean also noted she had gotten this feedback in focus groups:

When you visit a dataset landing page (ie /view/:pid), the document title doesn't change to reflect anything unique about the page, such as the title or citation string for the dataset.

Updating page titles dynamically to match the content has at least two advantages:

  1. It's easier for users to differentiate multiple tabs and windows simultaneously browsing the site
  2. It's possibly better for some SEO software. Currently, we don't seem to have any issues with Googlebot figuring out our titles but there's plenty of other SEO tools that might

As an exmple: https://arcticdata.io/catalog/view/doi%3A10.18739%2FA27H1DN5S has the title "Arctic Data Center", when it could have a title such as:

  1. McKenzie Kuhn, Ruth Varner, David Bastviken, Patrick Crill, Sally MacIntyre, et al. 2021. BAWLD-CH4: Methane Fluxes from Boreal and Arctic Ecosystems. Arctic Data Center. doi:10.18739/A27H1DN5S. - Arctic Data Center

  2. Kuhn et al. 2021. BAWLD-CH4: Methane Fluxes from Boreal and Arctic Ecosystems. - Arctic Data Center

  3. BAWLD-CH4: Methane Fluxes from Boreal and Arctic Ecosystems. - Arctic Data Center

(Votes for the above or offers of other ideas welcomed)

Places we could update the title dynamically might include:

As for implementation, I see two routes forward:

  1. Sprinkle in document.title = 'foo' changes throughout the codebase, remembering to reset it on navigation appropriately every time
  2. Hook into the Backbone router. I've seen some ad-hoc code but I ran across Backbonejs-Router-Title-Helper which is a very small dependency and looks to support our use case
  3. Hook into the AppView. See @laurenwalker 's comment below

@laurenwalker @csjx any thoughts on this? Anyone else's thoughts also welcome, esp wrt the title formats above.

laurenwalker commented 3 years ago

Sounds like a great idea to me. I think we could put a hook for this into the AppView, since it knows when a new view has been rendered. Then each view will have a function for constructing a title string. We have to wait for asynchronous requests, like to Solr to get the citation metadata, so each view will handle the title construction a bit differently.

laijasmine commented 3 years ago

I would vote for option 2!