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
f4bdfadd
Commit
f4bdfadd
authored
3 years ago
by
OndraRehounek
Browse files
Options
Downloads
Patches
Plain Diff
district & region: Import fancybox galleries
parent
07a6b2e7
No related branches found
No related tags found
2 merge requests
!468
Release
,
!459
district & region: fancybox galleries
Pipeline
#7572
passed
3 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shared/jekyll_import.py
+53
-32
53 additions, 32 deletions
shared/jekyll_import.py
with
53 additions
and
32 deletions
shared/jekyll_import.py
+
53
−
32
View file @
f4bdfadd
...
...
@@ -12,6 +12,7 @@ from http.client import InvalidURL
from
io
import
StringIO
from
typing
import
List
from
urllib.error
import
HTTPError
from
uuid
import
uuid4
import
markdown.serializers
import
yaml
...
...
@@ -387,15 +388,40 @@ class JekyllArticleImporter:
text
=
re
.
split
(
r
"
^\s*$
"
,
text
.
strip
(),
flags
=
re
.
MULTILINE
)[
0
]
return
plain_md
.
convert
(
text
)
def
handle_fancybox_gallery
(
self
,
article
,
meta
:
dict
):
def
handle_content
(
self
,
article
,
meta
:
dict
,
html
:
str
):
"""
Převádí naparsované html do stremfieldů.
Pokud meta info článku obsahuje
"
fancybox
"
- tzn. v článku je galerie,
tak nejdříve očistíme HTML od for loopů galerie a podtom
v
"
self.handle_fancybox_gallery
"
získáme JSON data pro GalleryBlock
z ArticleMixinu.
Pokud článek galerii nemá (drtivá většina), tak uložíme jako
RichText (block type text).
"""
if
meta
.
get
(
"
fancybox
"
,
None
):
# Galerie josu v HTML ve formě dvou "{% for" tagů,
# ty potřebujeme zahodit z texxtu
html
=
re
.
sub
(
"
{% for(.*?){% for(.*?){% endfor %}(.*?){% endfor %}
"
,
""
,
html
,
flags
=
re
.
DOTALL
,
)
if
"
{% for
"
in
html
:
# pro případ, že by byl jenom jeden
html
=
re
.
sub
(
"
{% for(.*?){% endfor %}
"
,
""
,
html
,
flags
=
re
.
DOTALL
)
text_data_dict
=
{
"
type
"
:
"
text
"
,
"
value
"
:
html
}
gallery_data_dict
=
self
.
handle_fancybox_gallery
(
article
,
meta
)
article
.
content
=
json
.
dumps
([
text_data_dict
,
gallery_data_dict
])
else
:
text_data_dict
=
{
"
type
"
:
"
text
"
,
"
value
"
:
html
}
article
.
content
=
json
.
dumps
([
text_data_dict
])
def
handle_fancybox_gallery
(
self
,
article
,
meta
:
dict
)
->
dict
:
for
gallery
in
meta
[
"
fancybox
"
]:
# gallery by měl být dict
o
name a img
# gallery by měl být dict
s
name a img
gallery_name
=
gallery
.
get
(
"
name
"
,
""
)
if
gallery_name
:
article
.
content
.
append
(
(
"
text
"
,
RichText
(
"
<h2>{}</h2>
"
.
format
(
gallery_name
)))
)
gallery_images
=
gallery
.
get
(
"
img
"
,
[])
if
not
len
(
gallery_images
):
...
...
@@ -425,26 +451,21 @@ class JekyllArticleImporter:
if
log_message
:
self
.
page_log
+=
"
{}: {}
"
.
format
(
article
.
title
,
log_message
)
data
=
{
"
type
"
:
"
gallery
"
,
"
value
"
:
{
"
gallery_items
"
:
[]},
"
id
"
:
str
(
uuid4
()),
}
if
not
wagtail_image_list
:
return
# article.content += [("gallery", GalleryBlock(local_blocks=(
# 'gallery_items', ListBlock(
# child_block=ImageChooserBlock()
# ) TODO use JSON
# )))]
data
=
(
"
gallery
"
,
[
{
"
gallery_items
"
:
[
# FIXME causing error 'list' object has no attribute 'items'
{
"
type
"
:
"
item
"
,
"
value
"
:
wagtail_image_list
[
0
].
id
}
]
}
],
)
return
data
article
.
content
.
append
(
json
.
dumps
(
data
))
print
(
article
.
content
)
for
image
in
wagtail_image_list
:
data
[
"
value
"
][
"
gallery_items
"
].
append
(
{
"
type
"
:
"
item
"
,
"
value
"
:
image
.
id
,
"
id
"
:
str
(
uuid4
())}
)
return
data
@staticmethod
def
handle_meta_is_str
(
meta
:
str
)
->
dict
:
...
...
@@ -516,10 +537,7 @@ class JekyllArticleImporter:
article
=
self
.
page_model
()
article
.
perex
=
self
.
get_perex
(
md
)
or
"
...
"
article
.
content
=
[(
"
text
"
,
RichText
(
html
))]
if
meta
.
get
(
"
fancybox
"
,
None
):
self
.
handle_fancybox_gallery
(
article
,
meta
)
self
.
handle_content
(
article
,
meta
,
html
)
if
meta
.
get
(
"
date
"
,
None
):
meta_date
=
meta
[
"
date
"
]
...
...
@@ -616,9 +634,12 @@ class JekyllArticleImporter:
try
:
article
.
save
()
# ujistím se, že mám "redirect_page" pro Redirect uloženou
except
:
pass
# self.create_redirects(article, match)
self
.
create_redirects
(
article
,
match
)
except
Exception
as
e
:
msg
=
"
{}: nelze uložit - {}
"
.
format
(
article
.
title
,
e
)
logger
.
error
(
msg
)
self
.
page_log
+=
"
{}
\n
"
.
format
(
msg
)
self
.
skipped_counter
+=
1
else
:
msg
=
"
Nepodporovaná přípona souboru: %s
"
%
ext
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