-
Notifications
You must be signed in to change notification settings - Fork 60
Support custom page icons and image overrides #417
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
Support custom page icons and image overrides #417
Conversation
RenderJSON spec for this change is up here: https://github.com/apple/swift-docc/pull/367/files#diff-5a65fbdff488799d5ec3462fe3145b2fa8d19a8e029cd568d12dc9fd5d613b46. I've added an |
Awesome. Added support for it. |
I haven't dug into the code review too much yet, but I started playing with this in combination with the corresponding DocC PR and I'm noticing some potential issues. It seems like only the icon in the navigator is being overwritten, and I think there are a couple of other places where this icon is being shown like the topics section and documentation intro. For those screenshots, I added a new # Formatting Your Documentation Content
@Metadata {
@PageImage(purpose: icon, source: "square.svg", alt: "A square icon")
}
Enhance your content's presentation with special formatting and styling for text, links, and other page elements. |
And my new icon looks like this for reference: <svg viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg" id="square">
<rect x="2" y="2" width="10" height="10" stroke="currentColor" fill="none"></rect>
</svg> Let me know if I misunderstood anything about this is expected to work. Thanks! |
Thanks for the review @mportiz08 I used Ethan's DocC branch to do a more real test, with actual data and I fixed the issues you pointed out. I am not super happy about how I got similar overriding logic in the two icon components, but I was not sure how to extract that away. I dont want to use mixins, yet we need a way to optionally render the override instead of the actual icon, while still applying classes and styling to both. |
Cool. It looks like the icon is being used in all the right places now that I highlighted in those screenshots. |
What is the expectation for this feature when combined with the (global) icon overriding from the theme-settings feature? For example, what if I add an overriding icon for a specific article and also override the default icon for all articles using |
Would a mixin solve the problem and you just prefer not to use them or is there an issue making them tricky to use here? Is there a solution where introducing a new component would simplify things or is there logic that could be moved to the base |
I think as you, that markdown specified icon should have weight over the globally replaced icon.
A mixin would probably help here, I am just not the biggest fan of them. I will keep you updated. |
OK refactored the duplicated logic out into a provider component, no magic mixins 🤨 Let me know if this is OK. |
Code looks good. I've been trying to test it using the |
I just went over them and re-build an archive of docc docs for you. You can also try out using the docc PR. |
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.
Tested and works great!
@swift-ci test |
Adds a new `@PageImage` directive that can be placed inside a page’s @metadata directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s @metadata directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s @metadata directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s `@Metadata` directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s `@Metadata` directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s `@Metadata` directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s `@Metadata` directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Adds a new `@PageImage` directive that can be placed inside a page’s `@Metadata` directive block to allow for customizing the images that will be used to represent the page in the navigator, hero, and elsewhere in the UI. For article-only catalogs it’s likely helpful to distinguish between articles with custom icons- in the same way Swift-DocC has different icons for different kinds of symbol pages. `@PageImage` accepts the following parameters: - purpose: The purpose of the image. One of the following: - icon: This image should be used in place of wherever a generic icon for the page would usually be rendered. - card: This image should be used whenever rendering a card representing this page. - source: A string containing the name of an image in your DocC catalog. - alt: (optional) A string containing a description of the image. Example: # Feeding a Sloth @metadata { @PageImage(purpose: icon, source: "leaf.svg", alt: "An icon representing a leaf.") } `@PageImage` is described on the Swift forums here: https://forums.swift.org/t/supporting-more-types-of-documentation-with-swift-docc/59725#pageimage-22 Dependencies: - swiftlang/swift-docc-render#417 Resolves rdar://97739580
Bug/issue #, if applicable: 97715925
Summary
Allow overriding the icons and images related to a page. These can be navigator icon, DocumentationHero icon or the Topics links.
Note 1
This PR sort of builds upon the #402, and more particularly the icon overriding. There should be minimal changed needed for both to co-exist.
Dependencies
#402
DocC PR - swiftlang/swift-docc#367
Testing
Use the DocC PR to build an archive with image overrides or use the attached one below
archive_with_icon_override.zip
Steps:
http://localhost:8081/documentation/docc/formatting-your-documentation-content
http://localhost:8081/documentation/docc/
the page above also has a changed icon in the Topic links.Checklist
npm test
, and it succeeded