-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: add asLinkAttrs()
helper
#282
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## v7 #282 +/- ##
========================================
Coverage 99.96% 99.96%
========================================
Files 46 48 +2
Lines 5138 5281 +143
Branches 288 303 +15
========================================
+ Hits 5136 5279 +143
Misses 2 2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the rel
value, any thought about having a similar asImageAttrs
helper also? asImageWidthSrcSet
and asImagePixelDensitySrcSet
could also return alt
value 🤔
I updated the PR with a new See the updated PR body for details.
Makes sense to me! We will brainstorm a list of new helpers and implement them as time allows. In general, having these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Types of changes
Description
This PR adds a new
asLinkAttrs()
helper. It complements theasLink()
helper.asLinkAttrs()
accepts a Link field or a Prismic document and returns an object of link attributes.The resulting
href
,target
, andrel
attributes can be passed to an<a>
element or similar link components (e.g. Next.js'next/link
component).rel
attributeThe
rel
value resolves to a good default: if thehref
is external (i.e. starts with a protocol likehttps://
),rel
is"noreferrer"
.The
rel
value can be configured using therel
option:The value returned by the function is exactly what is returned for the
rel
value; the automaticnoreferrer
logic described above is omitted.Note that browsers imply the
"noopener"
value whenrel
is"noreferrer"
ortarget
is_blank
.Link Resolver
A Link Resolver can be provided to compute a field or document's
href
.Prefer using Route Resolver and reserving Link Resolver only for unusual cases.
Checklist:
🦭