AlexsLemonade / refinebio-web

Refinebio Web
https://staging.web.refine.bio
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Add getPageTitle helper to the PageTitle component #387

Open nozomione opened 3 weeks ago

nozomione commented 3 weeks ago

Context

Currently, we use a switch statement and regex patterns to determine the prefix for each page's <title /> HTML tag for SEO in the PageTitle component.


  switch (true) {
    case title.length > 0:
      pageTitle = `${title}`
      break
    case home:
      pageTitle = `${appName} - Search for harmonized transcriptome data`
      break
    case /\/about$/.test(path):
      pageTitle = `About`
      break
    case /\/dataset/.test(path):
      pageTitle = `Dataset -`
      break
    case /\/download/.test(path):
      pageTitle = `Download Dataset -`
      break
    case /\/license$/.test(path):
      pageTitle = `License -`
      break
    case /\/privvacy$/.test(path):
      pageTitle = `Privacy -`
      break
    case /\/terms$/.test(path):
      pageTitle = `Terms of Use -`
      break
    default:
      break
  }

In this issue, we want to replace the switch with an if statement, and instead of using regex, we'll define all prefix values for the pages using an object.

Problem or idea

To achieve this, we should make the following changes to PageTitle:

Solution or next step

In PageTitle:

  1. Add a new constant object,titlePrefixes, to store prefix values for pages
  2. Add a new helper getPageTitle that does the following:
    • Takes a route path as its argument
    • Returns the corresponding prefix value using if and titlePrefixes