mirror of
https://github.com/grey-cat-1908/website.git
synced 2024-11-14 20:17:27 +03:00
test && preview gallery
This commit is contained in:
parent
c07a513704
commit
5156f001ee
8 changed files with 90 additions and 7 deletions
36
build.py
36
build.py
|
@ -23,13 +23,16 @@ markdown_renderer = mistune.create_markdown(
|
||||||
shutil.rmtree("build", ignore_errors=True)
|
shutil.rmtree("build", ignore_errors=True)
|
||||||
os.makedirs("build")
|
os.makedirs("build")
|
||||||
|
|
||||||
with open("template.html", "r") as template_file:
|
with open("templates/general.html", "r") as template_file:
|
||||||
template_text = template_file.read()
|
template_text = template_file.read()
|
||||||
|
|
||||||
with open("blog_template.html", "r") as blog_template_file:
|
with open("templates/blog.html", "r") as blog_template_file:
|
||||||
blog_template_text = blog_template_file.read()
|
blog_template_text = blog_template_file.read()
|
||||||
|
|
||||||
with open("meta.json", "r") as meta_file:
|
with open("templates/gallery.html", "r") as gallery_template_file:
|
||||||
|
gallery_template_text = gallery_template_file.read()
|
||||||
|
|
||||||
|
with open("templates/meta.json", "r") as meta_file:
|
||||||
base_meta = json.load(meta_file)
|
base_meta = json.load(meta_file)
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +49,7 @@ def parse_meta(meta_data):
|
||||||
return "".join(meta_tags)
|
return "".join(meta_tags)
|
||||||
|
|
||||||
|
|
||||||
def generate_html_content(directory, filename, is_blog=False):
|
def generate_html_content(directory, filename, status=0):
|
||||||
"""Generate HTML content from a markdown file and metadata."""
|
"""Generate HTML content from a markdown file and metadata."""
|
||||||
file_path = os.path.join(directory, filename)
|
file_path = os.path.join(directory, filename)
|
||||||
|
|
||||||
|
@ -61,12 +64,25 @@ def generate_html_content(directory, filename, is_blog=False):
|
||||||
|
|
||||||
meta_data = parse_meta(meta)
|
meta_data = parse_meta(meta)
|
||||||
|
|
||||||
if is_blog:
|
if status == 1:
|
||||||
return (
|
return (
|
||||||
blog_template_text.replace("{{%CONTENT%}}", markdown_renderer(md_text))
|
blog_template_text.replace("{{%CONTENT%}}", markdown_renderer(md_text))
|
||||||
.replace("{{%TITLE%}}", meta.get("title", ""))
|
.replace("{{%TITLE%}}", meta.get("title", ""))
|
||||||
.replace("{{%META%}}", meta_data)
|
.replace("{{%META%}}", meta_data)
|
||||||
)
|
)
|
||||||
|
elif status == 2:
|
||||||
|
gallery_path = os.path.join(directory, "gallery.data")
|
||||||
|
gallery = "[]"
|
||||||
|
if os.path.exists(gallery_path):
|
||||||
|
with open(gallery_path, "r") as gallery_file:
|
||||||
|
gallery = gallery_file.read()
|
||||||
|
|
||||||
|
return (
|
||||||
|
gallery_template_text.replace("{{%CONTENT%}}", markdown_renderer(md_text))
|
||||||
|
.replace("{{%GALLERY%}}", gallery)
|
||||||
|
.replace("{{%TITLE%}}", meta.get("title", ""))
|
||||||
|
.replace("{{%META%}}", meta_data)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return minify_html.minify(
|
return minify_html.minify(
|
||||||
template_text.replace("{{%CONTENT%}}", markdown_renderer(md_text))
|
template_text.replace("{{%CONTENT%}}", markdown_renderer(md_text))
|
||||||
|
@ -100,13 +116,19 @@ def process_content_directory(source_dir, target_dir):
|
||||||
process_content_directory(source_path, target_path)
|
process_content_directory(source_path, target_path)
|
||||||
else:
|
else:
|
||||||
if filename.endswith(".md"):
|
if filename.endswith(".md"):
|
||||||
is_blog = "blog" in os.path.relpath(source_path, start="content").split(
|
par = os.path.relpath(source_path, start="content").split(
|
||||||
os.sep
|
os.sep
|
||||||
)
|
)
|
||||||
|
status = 0
|
||||||
|
|
||||||
|
if "blog" in par:
|
||||||
|
status = 1
|
||||||
|
if "gallery" in par and par[-2] != "gallery":
|
||||||
|
status = 2
|
||||||
|
|
||||||
html_filename = os.path.splitext(filename)[0] + ".html"
|
html_filename = os.path.splitext(filename)[0] + ".html"
|
||||||
output_file = os.path.join(target_dir, html_filename)
|
output_file = os.path.join(target_dir, html_filename)
|
||||||
content = generate_html_content(source_dir, filename, is_blog=is_blog)
|
content = generate_html_content(source_dir, filename, status=status)
|
||||||
|
|
||||||
with open(output_file, "w") as file:
|
with open(output_file, "w") as file:
|
||||||
file.write(content)
|
file.write(content)
|
||||||
|
|
7
content/gallery/index.md
Normal file
7
content/gallery/index.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Gallery
|
||||||
|
|
||||||
|
This is the main page of my gallery. Here you can access all the albums of photos I post.
|
||||||
|
|
||||||
|
## List of albums:
|
||||||
|
|
||||||
|
- [Doha, Qatar 🇶🇦](https://mrkrk.me/gallery/qatar)
|
10
content/gallery/qatar/gallery.data
Normal file
10
content/gallery/qatar/gallery.data
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
src: "https://cdn.mrkrk.me/img/doha-qatar/im1.jpg",
|
||||||
|
subHtml: `<h4>Photo by <a href="https://mrkrk.me/">Viktor K.</a></h4><p>Published on November 06, 2024</p>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: "https://cdn.mrkrk.me/img/doha-qatar/im2.jpg",
|
||||||
|
subHtml: `<h4>Photo by <a href="https://mrkrk.me/">Viktor K.</a></h4><p>Published on November 06, 2024</p>`,
|
||||||
|
}
|
||||||
|
]
|
3
content/gallery/qatar/index.md
Normal file
3
content/gallery/qatar/index.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Doha, Qatar 🇶🇦
|
||||||
|
|
||||||
|
Click on the button to open the gallery and view the photos:
|
41
templates/gallery.html
Normal file
41
templates/gallery.html
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
{{%META%}}
|
||||||
|
<link rel="stylesheet" href="/custom.css">
|
||||||
|
<link rel="icon" href="/favicon.ico">
|
||||||
|
<title>{{%TITLE%}}</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.7.2/css/lightgallery.min.css" integrity="sha512-F2E+YYE1gkt0T5TVajAslgDfTEUQKtlu4ralVq78ViNxhKXQLrgQLLie8u1tVdG2vWnB3ute4hcdbiBtvJQh0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.7.2/css/lg-zoom.min.css" integrity="sha512-vIrTyLijDDcUJrQGs1jduUCSVa3+A2DaWpVfNyj4lmXkqURVQJ8LL62nebC388QV3P4yFBSt/ViDX8LRW0U6uw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav>
|
||||||
|
<b>mrkrk</b>
|
||||||
|
<a href="/">Home</a>
|
||||||
|
<a href="/projects">Projects</a>
|
||||||
|
</nav>
|
||||||
|
<main class="mc">
|
||||||
|
{{%CONTENT%}}
|
||||||
|
<button id="gallery">Open Gallery</a>
|
||||||
|
</main>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.7.2/lightgallery.min.js" integrity="sha512-jEJ0OA9fwz5wUn6rVfGhAXiiCSGrjYCwtQRUwI/wRGEuWRZxrnxoeDoNc+Pnhx8qwKVHs2BRQrVR9RE6T4UHBg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/2.7.2/plugins/zoom/lg-zoom.min.js" integrity="sha512-BLW2Jrofiqm6m7JhkQDIh2olT0EBI58+hIL/AXWvo8gOXKmsNlU6myJyEkTy6rOAAZjn0032FRk8sl9RgXPYIQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
const $dynamicGallery = document.getElementById("gallery");
|
||||||
|
const dynamicGallery = window.lightGallery($dynamicGallery, {
|
||||||
|
licenseKey: "878B9FB0-9D9145BB-819AB58C-184A267D",
|
||||||
|
download: false,
|
||||||
|
dynamic: true,
|
||||||
|
plugins: [lgZoom],
|
||||||
|
dynamicEl: {{%GALLERY%}}
|
||||||
|
});
|
||||||
|
$dynamicGallery.addEventListener("click", () => {
|
||||||
|
dynamicGallery.openGallery(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue