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
4b496099
Commit
4b496099
authored
3 years ago
by
Štěpán Farka
Committed by
jan.bednarik
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[ADD] support for stredocesky, nested folders
parent
dde57255
Branches
Branches containing commit
No related tags found
2 merge requests
!442
Release
,
!432
Feature/majak imports
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
district/jekyll_import.py
+83
-39
83 additions, 39 deletions
district/jekyll_import.py
with
83 additions
and
39 deletions
district/jekyll_import.py
+
83
−
39
View file @
4b496099
...
...
@@ -58,6 +58,7 @@ class ImgProcessor(InlineProcessor):
el
.
attrib
[
"
alt
"
]
=
m
.
group
(
1
)
el
.
attrib
[
"
format
"
]
=
"
left
"
collection
=
get_collection
()
# TODO FIX REPO_NAME
image_obj
=
get_or_create_image
(
params
[
"
path
"
],
m
.
group
(
2
),
collection
=
collection
,
repo_name
=
""
)
...
...
@@ -198,8 +199,8 @@ def get_or_create_image(path, file_path, collection, repo_name) -> Image or None
except
FileNotFoundError
:
img_name
=
file_path
.
split
(
"
/
"
)[
-
1
]
img_assets_folder
=
repo_name
.
split
(
"
.
"
)[
0
]
# TODO make as form field
img_url
=
"
https://a.pirati.cz/{}/img/
posts/
{}
"
.
format
(
img_assets_folder
,
img_name
img_url
=
"
https://a.pirati.cz/{}/img/{}
"
.
format
(
img_assets_folder
,
file_path
)
img_path
=
os
.
path
.
join
(
path
,
img_name
)
try
:
...
...
@@ -290,7 +291,58 @@ def perform_import(
articlepath
=
site_config
.
get
(
"
articlepath
"
,
"
aktuality
"
)
for
fn
in
os
.
listdir
(
os
.
path
.
join
(
path
,
POSTS_DIR
)):
fname
=
os
.
path
.
join
(
POSTS_DIR
,
fn
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
path
,
POSTS_DIR
,
fn
)):
posts_sub_folder
=
os
.
path
.
join
(
path
,
POSTS_DIR
,
fn
)
for
sub_fn
in
os
.
listdir
(
posts_sub_folder
):
file_path
=
os
.
path
.
join
(
posts_sub_folder
,
sub_fn
)
success_counter
=
article_parser
(
articlepath
,
path
,
sub_fn
,
file_path
,
article_parent_page
,
title_suffix
,
dry_run
,
repo_name
,
success_counter
,
site
,
)
else
:
file_path
=
os
.
path
.
join
(
POSTS_DIR
,
fn
)
success_counter
=
article_parser
(
articlepath
,
path
,
fn
,
file_path
,
article_parent_page
,
title_suffix
,
dry_run
,
repo_name
,
success_counter
,
site
,
)
if
success_counter
:
base_msg
=
"
Lze importovat
"
if
dry_run
else
"
Úspěšně naimportováno
"
message_list
.
append
(
{
"
level
"
:
SUCCESS
,
"
text
"
:
"
{} {} článků
"
.
format
(
base_msg
,
success_counter
)}
)
return
message_list
def
article_parser
(
articlepath
:
str
,
path
:
str
,
fn
,
file_path
,
article_parent_page
,
title_suffix
,
dry_run
,
repo_name
,
success_counter
,
site
,
):
match
=
re
.
match
(
r
"
(\d*)-(\d*)-(\d*)-(.*)\.(.*)
"
,
fn
)
if
match
:
y
=
match
.
group
(
1
)
...
...
@@ -301,15 +353,14 @@ def perform_import(
if
ext
==
"
md
"
:
article
,
success
=
import_post
(
path
,
f
name
,
article_parent_page
,
title_suffix
,
dry_run
,
repo_name
path
,
f
ile_path
,
article_parent_page
,
title_suffix
,
dry_run
,
repo_name
)
if
not
success
:
cont
inu
e
return
success_
co
u
nte
r
if
dry_run
:
success_counter
+=
1
continue
return
success_counter
+
1
Redirect
.
objects
.
get_or_create
(
site
=
site
,
...
...
@@ -329,11 +380,4 @@ def perform_import(
if
dry_run
:
message_list
.
append
({
"
level
"
:
WARNING
,
"
text
"
:
msg
})
if
success_counter
:
base_msg
=
"
Lze importovat
"
if
dry_run
else
"
Úspěšně naimportováno
"
message_list
.
append
(
{
"
level
"
:
SUCCESS
,
"
text
"
:
"
{} {} článků
"
.
format
(
base_msg
,
success_counter
)}
)
return
message_list
return
success_counter
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