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

Fix title in index.html to be ZIM title #250

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
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
26 changes: 21 additions & 5 deletions scraper/src/youtube2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,27 @@
continue
path = str(Path(file).relative_to(self.zimui_dist))
logger.debug(f"Adding {path} to ZIM")
self.zim_file.add_item_for(
path,
fpath=file,
is_front=path == "index.html",
)
if path == "index.html": # Change index.html title and add to ZIM
index_html_path = self.zimui_dist / path
html_content = index_html_path.read_text(encoding="utf-8")
new_html_content = re.sub(

Check warning on line 434 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L432-L434

Added lines #L432 - L434 were not covered by tests
r"(<title>)(.*?)(</title>)",
rf"\1{self.title}\3",
html_content,
flags=re.IGNORECASE,
)
self.zim_file.add_item_for(

Check warning on line 440 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L440

Added line #L440 was not covered by tests
path=path,
content=new_html_content,
mimetype="text/html",
is_front=True,
)
else:
self.zim_file.add_item_for(

Check warning on line 447 in scraper/src/youtube2zim/scraper.py

View check run for this annotation

Codecov / codecov/patch

scraper/src/youtube2zim/scraper.py#L447

Added line #L447 was not covered by tests
path,
fpath=file,
is_front=False,
)

def s3_credentials_ok(self):
logger.info("testing S3 Optimization Cache credentials")
Expand Down
Loading