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

[titles] Add updating titles to each pages #925

Merged
merged 2 commits into from
Nov 19, 2024
Merged

Conversation

gregnazario
Copy link
Contributor

Description

Adds titles to each page, I'm not sure I really know what I'm doing here with all the use effects, but it does seem to work decently.

I observed google searches don't give good title names, so adding this will help the google web crawler to give better names

Related Links

Checklist

Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for aptos-explorer ready!

Name Link
🔨 Latest commit acf6f51
🔍 Latest deploy log https://app.netlify.com/sites/aptos-explorer/deploys/673d08225a09fe00089d6ea8
😎 Deploy Preview https://deploy-preview-925--aptos-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kaw2k
Copy link
Contributor

kaw2k commented Nov 19, 2024

Great work! And useEffect is an appropriate use case here. An alternative (not saying to do it) is to use something like react-helmate. I think we should stick with your approach, but abstract it just a touch. I would recommend a hook like the following:

import { useEffect } from 'react'

interface PageMetadataArgs {
  title?: string
}

export function usePageMetadata(args: PageMetadataArgs = {}): void {
  useEffect(() => {
    document.title = args.title ? `${args.title} | Aptos Explorer` : 'Aptos Explorer'
  }, [args]);
};

Note, page titles typically go from most specific to least specific. You could change title from string to string | string[] and chain them if you wanted, but typically you want titles under 60 characters for proper rendering in tabs.

This would also let us attach other metadata to the document in the future, twitter tags, facebook tags, etc.

@gregnazario gregnazario enabled auto-merge (squash) November 19, 2024 21:53
@gregnazario gregnazario merged commit 01e53f2 into main Nov 19, 2024
7 checks passed
@gregnazario gregnazario deleted the improve-titles branch November 19, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants