Skip to content

Inactivate known external links when needed #873

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

Closed

Conversation

mportiz08
Copy link
Contributor

@mportiz08 mportiz08 commented Jun 26, 2024

Bug/issue #, if applicable: 118834404

Summary

This adds logic to inactivate links to pages from other targets unless they have been included in the same combined archive.

Dependencies

swiftlang/swift-docc-plugin#84

Testing

You can use the archives from this fixture for the convenience of testing purposes:
archives.zip

Steps:

  1. Run VUE_APP_DEV_SERVER_PROXY=/path/to/Combined\ ExternalLinks\ Documentation.doccarchive npm run serve and open http://localhost:8080/documentation/outer/outerclass/dosomething(with:)
  2. Verify that all the links to "Inner" pages work, including in the declaration
  3. Run VUE_APP_DEV_SERVER_PROXY=/path/to/Outer.doccarchive npm run serve and open http://localhost:8080/documentation/outer/outerclass/dosomething(with:)
  4. Verify that all the links to "Inner" pages are no longer linked
  5. Check for any other regressions with links and linked declaration types using other fixture content.

Known issues:
Due to the way that the Render JSON and Navigator JSON are loaded independently by the renderer, it's possible that the links in step 4 may be initially linked for a very brief moment until the navigator has finished loading. I've discussed this with @d-ronnqvist, and this limitation is acceptable for now given the way that things are structured.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

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

mportiz08 added 11 commits June 26, 2024 11:11
When multiple targets that reference each other are compiled together
using the experimental DocC support, this array will indicate which
targets are available for linking purposes.

This allows the renderer to inactivate links in the situation where a
single target is being presented on its own and therefore cannot link to
the other target.
Copy link
Contributor

@hqhhuang hqhhuang left a comment

Choose a reason for hiding this comment

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

  1. Do we plan to have a separate PR for known external asset references? Or is that not a concern?
  2. We use the Reference component in couple of other places, like tutorials, button link, cards, mentioned in, relationships, etc. Do we also need to make this change there? or is it only a concern for links in the primary content and declarations?
  3. I tried my best to understand why this is needed, but I obviously don't have all the context. Maybe this won't work for obvious reasons I'm not aware of. But have you considered maybe removing items from the references object if their module name is not included in the includedArchiveIdentifiers list? Then we just let existing logic in each component to take over.

const { includedArchiveIdentifiers = [] } = context;
return !!(includedArchiveIdentifiers.length && (
!includedArchiveIdentifiers.some(id => (
identifier?.startsWith(`doc://${id}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Do we need to worry about capitalization here?
  2. I think we need to check if the identifier starts with doc://${id}/documentation. Just to make sure that the id matches exactly. (For example, Foo and FooBar)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Capitalization would be matched exactly as-is here. I don't think we would want to be less strict since we're given the exact identifier.
  2. That would only work for documentation pages and not tutorial pages. We could make this more strict, but I think checking for the special scheme and bundle ID should be sufficient (@d-ronnqvist correct me if I'm wrong)

@mportiz08
Copy link
Contributor Author

  1. Do we plan to have a separate PR for known external asset references? Or is that not a concern?

I don't believe that's a concern but @d-ronnqvist let me know if I'm mistaken.

  1. We use the Reference component in couple of other places, like tutorials, button link, cards, mentioned in, relationships, etc. Do we also need to make this change there? or is it only a concern for links in the primary content and declarations?

The ContentNode change here is at a layer higher than Reference and determines which data gets passed to Reference, so it should apply anywhere that component is used, which I believe is sufficient (in addition to the declaration change).

  1. I tried my best to understand why this is needed, but I obviously don't have all the context. Maybe this won't work for obvious reasons I'm not aware of. But have you considered maybe removing items from the references object if their module name is not included in the includedArchiveIdentifiers list? Then we just let existing logic in each component to take over.

I haven't tried this, but this could potentially be a better approach, although it might be difficult to find the right layer to add this logic. I can look into it.

@hqhhuang
Copy link
Contributor

hqhhuang commented Jul 1, 2024

  1. We use the Reference component in couple of other places, like tutorials, button link, cards, mentioned in, relationships, etc. Do we also need to make this change there? or is it only a concern for links in the primary content and declarations?

The ContentNode change here is at a layer higher than Reference and determines which data gets passed to Reference, so it should apply anywhere that component is used, which I believe is sufficient (in addition to the declaration change).

What about components that use Reference directly, not through ContentNode or LinkableToken like the examples I gave above? I'm not sure if those components can end up with external links though.

  1. I tried my best to understand why this is needed, but I obviously don't have all the context. Maybe this won't work for obvious reasons I'm not aware of. But have you considered maybe removing items from the references object if their module name is not included in the includedArchiveIdentifiers list? Then we just let existing logic in each component to take over.

I haven't tried this, but this could potentially be a better approach, although it might be difficult to find the right layer to add this logic. I can look into it.

I haven't thought too deeply into this, but maybe when we set references in the DocumentationTooicStore?

@mportiz08
Copy link
Contributor Author

  1. We use the Reference component in couple of other places, like tutorials, button link, cards, mentioned in, relationships, etc. Do we also need to make this change there? or is it only a concern for links in the primary content and declarations?

The ContentNode change here is at a layer higher than Reference and determines which data gets passed to Reference, so it should apply anywhere that component is used, which I believe is sufficient (in addition to the declaration change).

What about components that use Reference directly, not through ContentNode or LinkableToken like the examples I gave above? I'm not sure if those components can end up with external links though.

  1. I tried my best to understand why this is needed, but I obviously don't have all the context. Maybe this won't work for obvious reasons I'm not aware of. But have you considered maybe removing items from the references object if their module name is not included in the includedArchiveIdentifiers list? Then we just let existing logic in each component to take over.

I haven't tried this, but this could potentially be a better approach, although it might be difficult to find the right layer to add this logic. I can look into it.

I haven't thought too deeply into this, but maybe when we set references in the DocumentationTooicStore?

I think the referencesProvider mixin was the right place to do this. I've opened an alternate PR with that approach: #878 — let me know what you think (I think I prefer this approach as well).

@mportiz08
Copy link
Contributor Author

Closing in favor of #878

@mportiz08 mportiz08 closed this Jul 9, 2024
@hqhhuang hqhhuang mentioned this pull request Jul 9, 2024
3 tasks
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.

2 participants