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

Update & Expand Meta Tags #49872

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

solonovamax
Copy link

@solonovamax solonovamax commented Dec 15, 2024

Summary

Improves/expands the meta tags for shared files.

  • Adds the following opengraph tags, depending on the file type
    • images:
      • og:image:type: the mimetype of the image file (TODO: should this be added for all shared files? all files will always have an og:image tag with either the preview or the nc logo)
    • audio:
      • og:audio: a direct link to the audio file
      • og:audio:type: the mimetype of the audio file
    • video:
      • og:video: a direct link to the video file
      • og:video:type: the mimetype of the video file
  • Updates the og:type tag from object (which is not a type that exists, as far as I can tell) to website
  • Adds meta tags for twitter
    • twitter:title: same as og:title
    • twitter:description: same as og:description
    • twitter:card: summary_large_image if the shared file is an image & it has a preview, otherwise summary
    • twitter:image: same as og:image

Before changes

Image

After changes

Note

I tested this on my personal self-hosted nextcloud, which is running nextcloud 29.0.10. I did this by just manually editing the apps/files_sharing/lib/DefaultPublicShareTemplateProvider.php file.

image

Checklist

@solracsf solracsf linked an issue Dec 15, 2024 that may be closed by this pull request
@solracsf

This comment was marked as resolved.

@solracsf solracsf added this to the Nextcloud 31 milestone Dec 15, 2024
@solracsf solracsf added the 3. to review Waiting for reviews label Dec 15, 2024
@solonovamax solonovamax force-pushed the master branch 2 times, most recently from dc9182d to 2a53ae7 Compare December 15, 2024 19:29
@solonovamax
Copy link
Author

Applied requested changes.

@solonovamax
Copy link
Author

solonovamax commented Dec 15, 2024

I've also added some additional changes to the opengraph meta tags. I will update the title/description in 15-20 with the additional changes.

Edit: updated

@solonovamax solonovamax changed the title Add Twitter Meta Tags Update & Expand Meta Tags Dec 15, 2024
@solonovamax
Copy link
Author

solonovamax commented Dec 15, 2024

oops, accidentally left in some funny formatting. I'll fix that in a bit.
Edit: fixed

other than that, the other failing checks seem to be either flaky tests, broken tests, or checks which won't run on forks.

Comment on lines +255 to +258
Util::addHeader('meta', ['property' => 'twitter:title', 'content' => $title]);
Util::addHeader('meta', ['property' => 'twitter:description', 'content' => $description]);
Util::addHeader('meta', ['property' => 'twitter:card', 'content' => $hasImagePreview ? 'summary_large_image' : 'summary']);
Util::addHeader('meta', ['property' => 'twitter:image', 'content' => $ogPreview]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding twitter specific tags? Can’t it read the standard tags?

Copy link
Member

Choose a reason for hiding this comment

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

They're not optimized. See screenshots in 1st post.

Copy link
Author

Choose a reason for hiding this comment

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

Why are we adding twitter specific tags? Can’t it read the standard tags?

It can, however imo it doesn't look as nice. yes, technically only the twitter:card tag is needed as it will fall back to the opengraph tags, however there is no harm in including them. (& there may be some services which only support the twitter tags, or if one of the twitter tags is present, it only uses twitter tags. unsure, as I have not tested this)

Adds the following twitter meta tags
- `twitter:card`: `summary_large_image` if the shared file is an image & it has a preview, otherwise `summary`
- `twitter:title`: same as `og:title`
- `twitter:description`: same as `og:description`
- `twitter:image`: same as `og:image`

Fixes nextcloud#49871

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
…pengraph type to website

- Adds the following opengraph tags
  - images:
    - `og:image:type`: the mimetype of the image file
  - audio:
    - `og:audio`: a direct link to the audio file
    - `og:audio:type`: the mimetype of the audio file
  - video:
    - `og:video`: a direct link to the video file
    - `og:video:type`: the mimetype of the video file
- Changes th `og:type` meta tag from `object` (which is not valid) to `website`

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Twitter Meta Tags
3 participants