Skip to content

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

Conversation

dobromir-hristov
Copy link
Contributor

@dobromir-hristov dobromir-hristov commented Aug 22, 2022

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.

image

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:

  1. Point docc-render's serve to the archive of your choice
  2. Go to a page that has page overrides, in my case http://localhost:8081/documentation/docc/formatting-your-documentation-content
  3. Assert the icon gets changed in both Navigator and DocumentationHero.
  4. Assert that when visiting http://localhost:8081/documentation/docc/ the page above also has a changed icon in the Topic links.

Checklist

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary

@ethan-kusters
Copy link
Contributor

RenderJSON spec for this change is up here: https://github.com/apple/swift-docc/pull/367/files#diff-5a65fbdff488799d5ec3462fe3145b2fa8d19a8e029cd568d12dc9fd5d613b46.

I've added an svgID property that just pulls the first ID we find in the given SVG file to support what we need for the theming infrastructure.

@dobromir-hristov
Copy link
Contributor Author

dobromir-hristov commented Sep 6, 2022

I've added an svgID property that just pulls the first ID we find in the given SVG file to support what we need for the theming infrastructure.

Awesome. Added support for it.

@mportiz08
Copy link
Contributor

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.

Examples:
Screenshot 2022-09-09 at 3 20 01 PM
Screenshot 2022-09-09 at 3 22 55 PM

For those screenshots, I added a new square.svg asset to the bundle and included the following directive in an article like so:

# 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.

@mportiz08
Copy link
Contributor

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!

@dobromir-hristov
Copy link
Contributor Author

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.

@mportiz08
Copy link
Contributor

Cool. It looks like the icon is being used in all the right places now that I highlighted in those screenshots.

@mportiz08
Copy link
Contributor

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 theme-settings.json? Personally, I would expect the icon specified in the markdown directive to still have priority and only be shown for that one particular article, but I just want to make sure that's how it's expected to work. I could probably test this out, but I'd need to do a test branch to combine this and the theme-settings PR I think since this isn't directly dependent on that branch as of now.

@mportiz08
Copy link
Contributor

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.

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 SVGIcon component to eliminate the repetition? (I'm not sure of the right answer myself off the top of my head, just throwing out some ideas in case something helps)

@dobromir-hristov
Copy link
Contributor Author

What is the expectation for this feature when combined with the (global) icon overriding from the theme-settings feature?

I think as you, that markdown specified icon should have weight over the globally replaced icon.

Would a mixin solve the problem and you just prefer not to use them

A mixin would probably help here, I am just not the biggest fan of them. I will keep you updated.

@dobromir-hristov
Copy link
Contributor Author

OK refactored the duplicated logic out into a provider component, no magic mixins 🤨

Let me know if this is OK.

@marinaaisa
Copy link
Member

Code looks good. I've been trying to test it using the SlothCreator_with_image_overrides.doccarchive you attached but it seems that the data is not updated or overwritting.
Is the testing steps updated?

@dobromir-hristov
Copy link
Contributor Author

Is the testing steps updated?

I just went over them and re-build an archive of docc docs for you. You can also try out using the docc PR.

Copy link
Member

@marinaaisa marinaaisa left a 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!

@dobromir-hristov
Copy link
Contributor Author

@swift-ci test

@dobromir-hristov dobromir-hristov merged commit 956a495 into swiftlang:main Sep 15, 2022
@dobromir-hristov dobromir-hristov deleted the dhristov/r97715925-support-custom-page-icon branch September 15, 2022 16:01
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 15, 2022
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
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 15, 2022
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
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 16, 2022
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
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 16, 2022
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
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 16, 2022
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
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 16, 2022
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
ethan-kusters added a commit to ethan-kusters/swift-docc that referenced this pull request Sep 16, 2022
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
ethan-kusters added a commit to swiftlang/swift-docc that referenced this pull request Sep 16, 2022
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
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.

4 participants