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
3ac12303
Commit
3ac12303
authored
3 years ago
by
Štěpán Farka
Committed by
jan.bednarik
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] markdown image, prague specifics
parent
4b496099
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
+61
-27
61 additions, 27 deletions
district/jekyll_import.py
with
61 additions
and
27 deletions
district/jekyll_import.py
+
61
−
27
View file @
3ac12303
...
...
@@ -6,7 +6,6 @@ import zipfile
from
datetime
import
date
from
http.client
import
InvalidURL
from
io
import
StringIO
from
shutil
import
rmtree
from
sys
import
stdout
from
typing
import
List
from
urllib.error
import
HTTPError
...
...
@@ -15,6 +14,7 @@ import markdown.serializers
import
yaml
from
django.contrib.messages
import
ERROR
,
INFO
,
SUCCESS
,
WARNING
from
django.core.files.images
import
ImageFile
from
django.utils
import
timezone
from
markdown
import
Markdown
from
markdown.extensions
import
Extension
from
markdown.inlinepatterns
import
InlineProcessor
...
...
@@ -59,8 +59,9 @@ class ImgProcessor(InlineProcessor):
el
.
attrib
[
"
format
"
]
=
"
left
"
collection
=
get_collection
()
# TODO FIX REPO_NAME
parsed_image_path
=
get_parsed_file_path
(
m
.
group
(
2
))
image_obj
=
get_or_create_image
(
params
[
"
path
"
],
m
.
group
(
2
)
,
collection
=
collection
,
repo_name
=
""
params
[
"
path
"
],
parsed_image_path
,
collection
=
collection
,
repo_name
=
""
)
if
not
image_obj
:
message_list
.
append
(
...
...
@@ -75,6 +76,17 @@ class ImgProcessor(InlineProcessor):
return
el
,
m
.
start
(
0
),
m
.
end
(
0
)
def
get_parsed_file_path
(
path
:
str
):
if
"
{{
"
in
path
:
try
:
parsed_path
=
path
.
split
(
"
{{
"
)[
1
].
split
(
"
|
"
)[
0
].
split
(
"'"
)[
1
]
except
IndexError
:
parsed_path
=
path
.
split
(
"
{{
"
)[
1
].
split
(
"
|
"
)[
0
].
split
(
'"'
)[
1
]
return
parsed_path
else
:
return
path
class
ImgExtension
(
Extension
):
def
extendMarkdown
(
self
,
md
):
IMG_PATTERN
=
r
"
!\[(.*?)\]\((.*?)\)
"
...
...
@@ -133,11 +145,14 @@ def import_post(path, file_path, parent, title_suffix, dry_run, repo_name):
article
.
content
=
[(
"
text
"
,
RichText
(
html
))]
article
.
perex
=
get_perex
(
md
)
if
meta
.
get
(
"
date
"
,
None
):
meta_date
=
meta
[
"
date
"
]
if
isinstance
(
meta_date
,
date
):
article
.
date
=
meta_date
else
:
article
.
date
=
meta
[
"
date
"
].
split
()[
0
]
else
:
article
.
date
=
timezone
.
now
()
article
.
title
=
meta
[
"
title
"
]
article
.
author
=
meta
.
get
(
"
author
"
,
"
Česká pirátská strana
"
)
...
...
@@ -196,6 +211,15 @@ def get_or_create_image(path, file_path, collection, repo_name) -> Image or None
image
=
Image
(
title
=
file_path
,
file
=
file
,
collection
=
collection
)
image
.
save
()
return
image
except
FileNotFoundError
:
try
:
file
=
ImageFile
(
open
(
os
.
path
.
join
(
path
,
"
assets/img
"
,
file_path
),
"
rb
"
),
name
=
file_path
,
)
image
=
Image
(
title
=
file_path
,
file
=
file
,
collection
=
collection
)
image
.
save
()
return
image
except
FileNotFoundError
:
img_name
=
file_path
.
split
(
"
/
"
)[
-
1
]
img_assets_folder
=
repo_name
.
split
(
"
.
"
)[
0
]
# TODO make as form field
...
...
@@ -239,10 +263,12 @@ def clone_repo(url: str) -> (str, str):
repo_name
=
url
.
split
(
"
/
"
)[
-
1
]
repo_path
=
os
.
path
.
join
(
path
,
repo_name
)
os
.
chdir
(
path
)
if
os
.
path
.
exists
(
repo_path
):
rmtree
(
repo_path
)
os
.
chdir
(
repo_path
)
os
.
system
(
"
git pull --depth 1
"
)
return
repo_path
,
repo_name
os
.
chdir
(
path
)
os
.
system
(
"
git clone --depth 1 {}
"
.
format
(
url
))
return
repo_path
,
repo_name
...
...
@@ -369,6 +395,14 @@ def article_parser(
defaults
=
{
"
is_permanent
"
:
True
,
"
redirect_page
"
:
article
},
)
# TODO handle redirects! PRAGUE X CB
# Redirect.objects.get_or_create(
# site=site,
# old_path="/%s/%s.html"
# % (articlepath, slug),
# defaults={"is_permanent": True, "redirect_page": article},
# )
success_counter
+=
1
else
:
msg
=
"
ERROR: Nepodporovaná přípona souboru: %s
"
%
ext
...
...
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