gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.75k stars 7.46k forks source link

feature request: social media URL parsing #11582

Open earthboundkid opened 11 months ago

earthboundkid commented 11 months ago

I have written Hugo sites where users can add social URLs. It would be nice if Hugo had a way to automatically parse them, so I can display {{ .username }} instead of http://example.com/username. You can do one off parsing for known sites like Facebook and Twitter if you know that's what it is ahead of time, but it's a lot of logic to shove into a template.

This project does the legwork already, so if it were added as a dependency, all that Hugo would have to do is expose it in the template function: https://github.com/FurqanSoftware/slinky

jmooring commented 11 months ago

Is this template function for convenience, instead of doing this in site configuration or on term page (e.g., content/authors/jmooring/_index.md)?

params:
  - social:
      handle: '@jmooring'
      url: https://github.com/jmooring/
  - social:
      handle: '@jmooring'
      url: https://social.vivaldi.net/@jmooring
earthboundkid commented 11 months ago

You can’t get users to input structured data.

jmooring commented 11 months ago

I would say you can't get some users to input structured data. Whether or not "some" represents a majority is debatable.

bep commented 11 months ago

I like this, and the library in question looks small and simple enough. I think there are plenty of Hugo use cases where the author struct could have a

links:
 -  https://github.com/jmooring/
  - https://social.vivaldi.net/@jmooring

Having a simple way to present that info would have value enough considering how relatively simple it would be to implement.

I guess something like this would make sense?

{{ with urls.ParseSocial $link }}
Service: {{ .Service }}
UserID: {{ .ID }}
{{ else }}
// Unknown URL format.
{{ end }}