Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
abe10271
Commit
abe10271
authored
3 years ago
by
OndraRehounek
Committed by
jan.bednarik
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Different zip names handled, different article URLs handled in redirects
parent
03d1d125
No related branches found
No related tags found
2 merge requests
!442
Release
,
!432
Feature/majak imports
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
district/jekyll_import.py
+27
-10
27 additions, 10 deletions
district/jekyll_import.py
with
27 additions
and
10 deletions
district/jekyll_import.py
+
27
−
10
View file @
abe10271
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment