-
Notifications
You must be signed in to change notification settings - Fork 15
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: Source specifying for relative links is allowed #232
base: master
Are you sure you want to change the base?
Changes from 1 commit
34aed04
c173010
11741eb
2bb8cb4
e7bd6c4
ff473b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OLX_STATIC_DIR = "static" | ||
OLX_STATIC_PATH_TEMPLATE = f"/{OLX_STATIC_DIR}/{{static_filename}}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from lxml import html | ||
from cc2olx.iframe_link_parser import KalturaIframeLinkParser | ||
|
||
from cc2olx.constants import OLX_STATIC_PATH_TEMPLATE | ||
from cc2olx.qti import QtiExport | ||
from cc2olx.utils import element_builder, passport_file_parser | ||
|
||
|
@@ -36,11 +37,12 @@ class OlxExport: | |
QTI = "qti" | ||
DISCUSSION = "discussion" | ||
|
||
def __init__(self, cartridge, link_file=None, passport_file=None): | ||
def __init__(self, cartridge, link_file=None, passport_file=None, relative_links_source=None): | ||
self.cartridge = cartridge | ||
self.doc = None | ||
self.link_file = link_file | ||
self.passport_file = passport_file | ||
self.relative_links_source = relative_links_source | ||
self.iframe_link_parser = None | ||
if link_file: | ||
self.iframe_link_parser = KalturaIframeLinkParser(self.link_file) | ||
|
@@ -250,6 +252,18 @@ def process_external_tools_link(item, html): | |
html = html.replace(item, external_tool_url) | ||
return html | ||
|
||
def process_extra_static_files(item, html): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a docstring here explaining what this function is for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if self.relative_links_source is None: | ||
return html | ||
|
||
for static_file in self.cartridge.extra_static_files: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How large can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During the resource content collection, when the external file is found, it's added to this list. So, the list size isn't limited and depends on CC archive content. But we need to process each such link to make it absolute, so we do need to iterate over the list. I don't think it's too expensive because other exporter tasks require much more actions to perform. Do you have any ideas how we can handle all the links without iterating over them? |
||
if item == OLX_STATIC_PATH_TEMPLATE.format(static_filename=static_file): | ||
return html | ||
|
||
url = urllib.parse.urljoin(self.relative_links_source, item) | ||
html = html.replace(item, url) | ||
return html | ||
|
||
for _, item in items: | ||
if "IMS-CC-FILEBASE" in item: | ||
html = process_ims_cc_filebase(item, html) | ||
|
@@ -259,6 +273,8 @@ def process_external_tools_link(item, html): | |
html = process_external_tools_link(item, html) | ||
elif "CANVAS_OBJECT_REFERENCE" in item: | ||
html = process_canvas_reference(item, html) | ||
else: | ||
html = process_extra_static_files(item, html) | ||
|
||
return html | ||
|
||
|
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.
Please add some validation for the format of
relative_links_source
.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.
Validation is added on the argument parsing step.