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
f1cc7c1c
Commit
f1cc7c1c
authored
3 years ago
by
OndraRehounek
Browse files
Options
Downloads
Patches
Plain Diff
jekyll-import: handle number as tag_name and images with absolute URL
parent
a6e8527f
Branches
Branches containing commit
No related tags found
2 merge requests
!484
release
,
!482
Bugfix/import zlinsky
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
shared/jekyll_import.py
+47
-18
47 additions, 18 deletions
shared/jekyll_import.py
with
47 additions
and
18 deletions
shared/jekyll_import.py
+
47
−
18
View file @
f1cc7c1c
...
@@ -151,16 +151,37 @@ def get_or_create_image(
...
@@ -151,16 +151,37 @@ def get_or_create_image(
except
FileNotFoundError
:
except
FileNotFoundError
:
pass
pass
#
ani cesta "assets/img/posts" nefunguje, jdeme zkusit assets server a.pirati.cz
#
na disku jsme nenašli, zkusíme stáhnout z webu
fallback_name
=
(
fallback_name
=
(
""
.
join
(
random
.
choice
(
string
.
ascii_lowercase
)
for
_
in
range
(
10
))
+
"
.jpg
"
""
.
join
(
random
.
choice
(
string
.
ascii_lowercase
)
for
_
in
range
(
10
))
+
"
.jpg
"
)
# někdy je název obrzau spojený s poznámkou apod., připravíme si fallback name
)
# někdy je název obrzau spojený s poznámkou apod., připravíme si fallback name
img_name
=
file_path
.
split
(
"
/
"
)[
-
1
]
or
fallback_name
img_name
=
file_path
.
split
(
"
/
"
)[
-
1
]
or
fallback_name
img_path
=
os
.
path
.
join
(
path
,
img_name
)
# zkusíme, jestli obrázek není hardcoded (posty ve zlinském kraji)
if
file_path
.
startswith
(
"
https://
"
):
try
:
urllib
.
request
.
urlretrieve
(
file_path
,
img_path
)
except
(
HTTPError
,
UnicodeEncodeError
,
InvalidURL
,
IsADirectoryError
):
msg
=
"
Nedohledán obrázek při importu článků - ani na disku, ani na URL
"
log_message
=
"
{}: URL {}
\n
"
.
format
(
msg
,
file_path
)
logger
.
warning
(
log_message
,
extra
=
{
"
file_path
"
:
file_path
,
"
img_name
"
:
img_name
,
"
img_url
"
:
file_path
,
},
)
return
None
,
log_message
# opačném případě jdeme zkusit assets server a.pirati.cz
else
:
img_assets_folder
=
repo_name
.
split
(
"
.
"
)[
0
]
# např. "praha" z praha.pirati.cz
img_assets_folder
=
repo_name
.
split
(
"
.
"
)[
0
]
# např. "praha" z praha.pirati.cz
img_url
=
"
https://a.pirati.cz/resize/4000x-/{}/img/{}
"
.
format
(
img_url
=
"
https://a.pirati.cz/resize/4000x-/{}/img/{}
"
.
format
(
img_assets_folder
,
file_path
.
split
(
"
#
"
)[
0
]
# cistime nazev od poznamek apod
img_assets_folder
,
file_path
.
split
(
"
#
"
)[
0
]
# cistime nazev od poznamek apod
)
)
img_path
=
os
.
path
.
join
(
path
,
img_name
)
try
:
try
:
urllib
.
request
.
urlretrieve
(
img_url
,
img_path
)
urllib
.
request
.
urlretrieve
(
img_url
,
img_path
)
except
(
HTTPError
,
UnicodeEncodeError
,
InvalidURL
,
IsADirectoryError
):
except
(
HTTPError
,
UnicodeEncodeError
,
InvalidURL
,
IsADirectoryError
):
...
@@ -498,10 +519,18 @@ class JekyllArticleImporter:
...
@@ -498,10 +519,18 @@ class JekyllArticleImporter:
meta_dict
.
update
({
key
:
value
})
meta_dict
.
update
({
key
:
value
})
return
meta_dict
return
meta_dict
@staticmethod
def
handle_tags
(
self
,
article
,
meta
):
def
handle_tags
(
article
,
meta
):
for
tag_name
in
meta
.
get
(
"
tags
"
,
[]):
for
tag_name
in
meta
.
get
(
"
tags
"
,
[]):
try
:
article
.
tags
.
add
(
tag_name
)
article
.
tags
.
add
(
tag_name
)
except
ValueError
:
try
:
article
.
tags
.
add
(
str
(
tag_name
))
except
Exception
as
E
:
msg
=
"
Nelze importovat tag
"
logger
.
warning
(
msg
,
extra
=
{
"
tag
"
:
tag_name
})
self
.
page_log
+=
"
{} - {}
\n
"
.
format
(
msg
,
tag_name
)
return
None
def
import_post
(
self
,
file_path
):
def
import_post
(
self
,
file_path
):
...
...
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