-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add external media support in documentation #82
Conversation
Implementation is almost done. Will update test and documentation later |
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.
I'm wondering if there's a way to implement this without new render reference types. Ideally the solution could be easily shared to also add support for external videos and external downloads (if that's something that we want to support)
Sources/SwiftDocC/Model/Rendering/References/ExternalImageReference.swift
Outdated
Show resolved
Hide resolved
Hi @Kyle-Ye, are you still working on this? Let @d-ronnqvist or I know we can help! |
Yes. Sorry for the late update (Busy with my full-time iOS RD internship recently) I have a few question here in order to better finish this PR and your review. After performing "docc preview" action to the xx.docc file, it will produce a For example if I have this markdown file in my xx.docc folder
It will produce something like this in reference part {
"https://www.swift.org/documentation/docc": {
"title": "DocC",
"titleInlineContent": [
{
"type": "text",
"text": "DocC"
}
],
"type": "link",
"identifier": "https://www.swift.org/documentation/docc",
"url": "https://www.swift.org/documentation/docc"
},
// MARK: - This is the current behavior. Without the PR, this item will not exist.
"https://www.swift.org/assets/images/swift.svg": {
"alt": "swift icon",
"type": "externalImage",
"identifier": "https://www.swift.org/assets/images/swift.svg",
"variants": [
{
"url": "https://www.swift.org/assets/images/swift.svg",
"traits": [
"1x",
"light"
]
}
]
},
"swift.svg": {
"alt": "swift icon",
"type": "image",
"identifier": "swift.svg",
"variants": [
{
"url": "/images/swift.svg",
"traits": [
"1x",
"light"
]
}
]
}
} I think "d-ronnqvist" is suggesting me to generate an item like this without introducing a new externalImage type, right? "https://www.swift.org/assets/images/swift.svg": {
"alt": "swift icon",
"type": "image",
"identifier": "https://www.swift.org/assets/images/swift.svg",
"variants": [
{
// MARK: Problem here, since in current design, for image type it'll do some magical logic here, how can we identity this is actually an external image? Do we need introduce a new field or just use host == nil?
"url": "https://www.swift.org/assets/images/swift.svg",
"traits": [
"1x",
"light"
]
}
]
}, |
ef1c258
to
45c5e22
Compare
Currently, I was stuck by the "display" and "download" context in DataAsset. Should externalImage a "display" context or "download" context? And what is "download" context mean in docc?
Appreciate for your help and clarification @franklinsch |
The old (working but rejected) implementation is at https://github.com/Kyle-Ye/swift-docc/tree/external-image-support_v1 |
I’ll look at this tomorrow |
From what I recall, this is an indication to Swift-DocC Render that has some impact on how the request for that access is made. @mportiz08 May be able to provide more information about how this information is used. A "download" context is used for zip archives and similar files that are downloaded but not displayed on the page and a "display" context is used for images and video that are displayed on the page. So in this case I would expect a "display" context. |
This will better indicate the type of reference and how it should be displayed or linked to for any renderers, including DocC-Render. The |
I think this could work by skipping copying assets that aren't local. There are a few places that inspect the URL to determine if it's a local asset or an external asset so maybe that could be used here as well. |
45c5e22
to
6aecffc
Compare
This PR adds external media support in documentation(docs and articles) but not in tutorials. Should we add support external media support for tutorials? And if we should maybe we can do it in a follow-up PR? cc @franklinsch |
Supporting external images in tutorials in a separate PR sounds good to me. Please make sure to file a ticket for it on bugs.swift.org to make sure we don't lose track of it :) |
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.
Thank you. This looks good to me.
I left a few comments and suggestions about some of the details.
Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertFileWritingConsumer.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Utility/FoundationExtensions/URL+IsAbsoluteWebURL.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Utility/FoundationExtensions/URL+IsAbsoluteWebURL.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Utility/FoundationExtensions/URL+IsAbsoluteWebURL.swift
Outdated
Show resolved
Hide resolved
6aecffc
to
3cceae5
Compare
3cceae5
to
e3e02d4
Compare
@swift-ci please test |
// If a scheme is present it means it's an absolute URL | ||
let isAbsoluteWebURL = !value.isFileURL && value.scheme?.isEmpty == false | ||
let url = isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent) | ||
let url = value.isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent) |
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.
URL.isAbsoluteWebURL delete the host check, otherwise it will fail on some test due to the case like 'docc-media:///path/a.png'. We can fix it by not using the URL.isAbsoluteWebURL API here. And I think it's better to use one uniformed API, so I delete the host check in URL.isAbsoluteWebURL. Any suggestion is welcomed.
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.
I agree that it's better to use the same API everywhere.
We can revisit the other tests' test data in the future to see if anything should be updated but I don't think that needs to happen now.
Finally fix all the test cases. Ready for the final review. @d-ronnqvist |
Update the original SR's title to "Add external media support for DocC documentation" and file up a new ticket to track the issue. https://bugs.swift.org/browse/SR-16026 |
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.
Thank you! This looks great to me.
// If a scheme is present it means it's an absolute URL | ||
let isAbsoluteWebURL = !value.isFileURL && value.scheme?.isEmpty == false | ||
let url = isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent) | ||
let url = value.isAbsoluteWebURL ? value : destinationURL(for: value.lastPathComponent) |
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.
I agree that it's better to use the same API everywhere.
We can revisit the other tests' test data in the future to see if anything should be updated but I don't think that needs to happen now.
e3e02d4
to
1d2503a
Compare
@swift-ci please test |
Bug/issue #, if applicable: SR-15839
Forum discussion: https://forums.swift.org/t/can-we-link-and-render-external-images-that-is-from-urls
Summary
Add a new ExternalMediaResolver to support external media reference.
Dependencies
None
Testing
Test external image and video support in docs and articles.
Checklist
./bin/test
script and it succeededTODO