Skip to content
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_description_long_description #183

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ celerybeat-schedule

# dotenv
.env
.venv

# virtualenv
venv/
Expand All @@ -91,4 +92,6 @@ openedx2zim/templates/assets/videojs/
openedx2zim/templates/assets/mathjax/
openedx2zim/templates/assets/ogvjs/
openedx2zim/templates/assets/jquery.min.js
openedx2zim/templates/assets/videojs-ogvjs.js
openedx2zim/templates/assets/videojs-ogvjs.js
openedx/openedx2zim.egg-info/
openedx/output/
7 changes: 7 additions & 0 deletions openedx2zim/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def main():
help="Custom description for your ZIM. Based on MOOC otherwise.",
)

##made changes here
parser.add_argument(
"--long-description",
help="Custom description for your ZIM,optional",
)


parser.add_argument("--creator", help="Name of content creator", default="edX")

parser.add_argument(
Expand Down
48 changes: 42 additions & 6 deletions openedx2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
VideoWebmHigh,
)
from zimscraperlib.zim import make_zim_file

from zimscraperlib.constants import (
MAXIMUM_DESCRIPTION_METADATA_LENGTH as MAX_DESC_LENGTH,
)
from zimscraperlib.constants import (
MAXIMUM_LONG_DESCRIPTION_METADATA_LENGTH as MAXIMUM_LONG_DESC_LENGTH,
)
from .annex import MoocForum, MoocWiki
from .constants import (
IMAGE_FORMATS,
Expand Down Expand Up @@ -85,6 +90,8 @@
"unavailable": Unavailable,
}



logger = getLogger()


Expand All @@ -101,6 +108,8 @@ def __init__(
name,
title,
description,
#added long_description here
joe-rabbit marked this conversation as resolved.
Show resolved Hide resolved
long_description,
creator,
publisher,
tags,
Expand Down Expand Up @@ -135,6 +144,8 @@ def __init__(
self.tags = [] if tags is None else [t.strip() for t in tags.split(",")]
self.title = title
self.description = description
#long description
joe-rabbit marked this conversation as resolved.
Show resolved Hide resolved
self.long_description = long_description
self.creator = creator
self.publisher = publisher
self.name = name
Expand Down Expand Up @@ -496,7 +507,7 @@ def get_favicon(self):
favicon_fpath = self.build_dir.joinpath("favicon.png")

# download the favicon
save_large_file(self.favicon_url, favicon_fpath)
save_large_file(self.favicon_url,favicon_fpath)
joe-rabbit marked this conversation as resolved.
Show resolved Hide resolved

# convert and resize
convert_image(favicon_fpath, favicon_fpath, fmt="PNG")
Expand Down Expand Up @@ -831,6 +842,24 @@ def render(self):
self.build_dir.joinpath("assets"),
)


def handle_descriptions(self, default_description, description=None, long_description=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I have handled this change

description = description or default_description[:MAX_DESC_LENGTH]
long_description = None

# checks the length of the description
if long_description:
if len(long_description) > MAXIMUM_LONG_DESC_LENGTH:
raise ValueError(
f"LongDescription too long ({len(long_description)}) > {MAXIMUM_LONG_DESC_LENGTH}"
)
long_description = long_description
elif len(default_description) > MAX_DESC_LENGTH:
long_description = default_description[MAX_DESC_LENGTH:]

return description, long_description


def get_zim_info(self):
if not self.has_homepage:
homepage = f"{self.head_course_xblock.relative_path}/index.html"
Expand All @@ -843,10 +872,16 @@ def get_zim_info(self):
else f"{self.course_info['name']} from {self.course_info['org']}"
)

description,long_description = self.handle_descriptions(
default_description = fallback_description,
description = self.description,
long_description = self.long_description
)


return {
"description": self.description
if self.description
else fallback_description,
"description": description,
"long-description" : long_description,
"title": self.title if self.title else self.course_info["name"],
"creator": self.creator if self.creator else self.course_info["org"],
"homepage": homepage,
Expand Down Expand Up @@ -902,9 +937,10 @@ def run(self):
fpath=self.output_dir.joinpath(self.fname),
name=self.name,
main_page=zim_info["homepage"],
favicon="favicon.png",
illustration="favicon.png",
title=zim_info["title"],
description=zim_info["description"],
long_description= zim_info["long-description"],
language=get_language_details(self.instance_lang)["iso-639-3"],
creator=zim_info["creator"],
publisher=self.publisher,
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Jinja2>=2.11.2,<2.12
mistune>=2.0.0a4,<2.1
requests>=2.24,<3.0
iso-639>=0.4.5,<0.5
zimscraperlib>=1.3.6,<1.4
zimscraperlib
joe-rabbit marked this conversation as resolved.
Show resolved Hide resolved
kiwixstorage>=0.3,<1.0
pif>=0.8.2,<0.9
xxhash>=2.0.0,<2.1
Expand All @@ -15,4 +15,4 @@ youtube_dl
# Jinja2 2.11 depends on soft_unicode which has been remove from markupsafe after 2.0.1
# so we pin the version to 2.0.1 ; this HAS to be removed once Jinja2 is update to a more
# recent version
markupsafe==2.0.1
markupsafe==2.0.1