Skip to content
Snippets Groups Projects
Commit abe10271 authored by OndraRehounek's avatar OndraRehounek Committed by jan.bednarik
Browse files

Different zip names handled, different article URLs handled in redirects

parent 03d1d125
No related branches found
No related tags found
2 merge requests!442Release,!432Feature/majak imports
...@@ -78,7 +78,20 @@ def download_repo_as_zip(url: str) -> (str, str): ...@@ -78,7 +78,20 @@ def download_repo_as_zip(url: str) -> (str, str):
with zipfile.ZipFile(zip_path, "r") as zip_ref: with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(path) zip_ref.extractall(path)
return os.path.join(path, "{}-gh-pages".format(repo_name)), repo_name # zdá se, že někdy je -gh-pages, někdy -master...
gh_pages_path = os.path.join(path, "{}-gh-pages".format(repo_name))
gh_pages_path_exists = os.path.exists(gh_pages_path)
master_path = os.path.join(path, "{}-master".format(repo_name))
master_path_exists = os.path.exists(master_path)
if gh_pages_path_exists:
return gh_pages_path, repo_name
if master_path_exists:
return master_path, repo_name
else:
raise NotImplementedError("Tento zip nedokážeme zpracovat.")
def get_or_create_image( def get_or_create_image(
...@@ -257,7 +270,8 @@ class JekyllArticleImporter: ...@@ -257,7 +270,8 @@ class JekyllArticleImporter:
self.site = article_parent_page.get_site() self.site = article_parent_page.get_site()
self.site_config = get_site_config(self.path) self.site_config = get_site_config(self.path)
self.article_path = self.site_config.get("articlepath", "aktuality") self.article_path = self.site_config.get("articlepath", None)
self.permalink = self.site_config.get("permalink", None)
self.title_suffix = get_title_from_site_config(self.site_config) self.title_suffix = get_title_from_site_config(self.site_config)
# Counters # Counters
...@@ -482,7 +496,10 @@ class JekyllArticleImporter: ...@@ -482,7 +496,10 @@ class JekyllArticleImporter:
if ext == "md": if ext == "md":
article = self.import_post(file_path) article = self.import_post(file_path)
if article: if self.dry_run:
return
if article and self.article_path: # asi hlavne Ceske Budejovice
Redirect.objects.get_or_create( Redirect.objects.get_or_create(
site=self.site, site=self.site,
old_path="/%s/%s/%s/%s/%s" old_path="/%s/%s/%s/%s/%s"
...@@ -490,13 +507,13 @@ class JekyllArticleImporter: ...@@ -490,13 +507,13 @@ class JekyllArticleImporter:
defaults={"is_permanent": True, "redirect_page": article}, defaults={"is_permanent": True, "redirect_page": article},
) )
# TODO handle redirects! PRAGUE X CB elif article and self.permalink:
# Redirect.objects.get_or_create( Redirect.objects.get_or_create(
# site=site, site=self.site,
# old_path="/%s/%s.html" old_path=self.permalink.replace(":title", slug),
# % (article_path, slug), defaults={"is_permanent": True, "redirect_page": article},
# defaults={"is_permanent": True, "redirect_page": article}, )
# )
else: else:
msg = "Nepodporovaná přípona souboru: %s" % ext msg = "Nepodporovaná přípona souboru: %s" % ext
logger.warning(msg) logger.warning(msg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment