mirror of
https://github.com/ZetaKebab/quartz.git
synced 2025-01-14 22:18:43 +00:00
Compare commits
9 Commits
c2dab1344e
...
1ce534d696
Author | SHA1 | Date | |
---|---|---|---|
1ce534d696 | |||
242bd75378 | |||
760cb91ad2 | |||
7d8cc8d0be | |||
51da3c172d | |||
2be716bf75 | |||
4cb6b5fa4c | |||
7108c68a7b | |||
5283a7e481 |
12
Dockerfile
12
Dockerfile
@ -1,3 +1,14 @@
|
|||||||
|
FROM python:latest as convert
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
COPY content/ ./
|
||||||
|
COPY custom/convert-furigana/program/convert-furigana.py ./
|
||||||
|
COPY custom/convert-usage/program/convert-usage.py ./
|
||||||
|
ENV PIP_ROOT_USER_ACTION=ignore
|
||||||
|
RUN python -m pip install --upgrade pip
|
||||||
|
RUN python -m pip install beautifulsoup4
|
||||||
|
RUN python convert-furigana.py .
|
||||||
|
RUN python convert-usage.py .
|
||||||
|
|
||||||
FROM node:20-slim as builder
|
FROM node:20-slim as builder
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
@ -8,4 +19,5 @@ FROM node:20-slim
|
|||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY --from=builder /usr/src/app/ /usr/src/app/
|
COPY --from=builder /usr/src/app/ /usr/src/app/
|
||||||
COPY . .
|
COPY . .
|
||||||
|
COPY --from=convert /usr/src/app/ /usr/src/app/content/
|
||||||
CMD ["npx", "quartz", "build", "--serve"]
|
CMD ["npx", "quartz", "build", "--serve"]
|
||||||
|
9
content/LICENSE
Normal file
9
content/LICENSE
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 keb
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3
content/README.md
Normal file
3
content/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# jpg-content
|
||||||
|
|
||||||
|
Markdown content of the Japanese Grammar (JPG) project
|
@ -1,2 +1,2 @@
|
|||||||
docker build -t quartz-jpg ..
|
docker build -t quartz-jpg .
|
||||||
docker-compose up -d --force-recreate
|
cd custom && docker-compose up -d --force-recreate
|
9
custom/convert-furigana/LICENSE
Normal file
9
custom/convert-furigana/LICENSE
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 keb
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
43
custom/convert-furigana/README.md
Normal file
43
custom/convert-furigana/README.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# convert-furigana
|
||||||
|
|
||||||
|
## What is it?
|
||||||
|
|
||||||
|
There are a few extensions that add [furigana](https://en.wikipedia.org/wiki/Furigana) support to Markdown. I use [Obsidian](https://obsidian.md/), and therefore its furigana extension: [obsidian-markdown-furigana](https://github.com/steven-kraft/obsidian-markdown-furigana). It works well, but by nature is limited by being used within Obsidian.
|
||||||
|
|
||||||
|
For that purpose, this python script converts this specific syntax to common, all-platforms HTML ruby tags.
|
||||||
|
|
||||||
|
## Process
|
||||||
|
|
||||||
|
This specific extension syntax is as following:
|
||||||
|
```
|
||||||
|
{漢字|かんじ}
|
||||||
|
{漢字|かん|じ}
|
||||||
|
```
|
||||||
|
|
||||||
|
When processed by this script, the result is:
|
||||||
|
```
|
||||||
|
<ruby>漢字<rt>かんじ</rt></ruby>
|
||||||
|
<ruby>漢<rt>かん</rt>字<rt>じ</rt></ruby>
|
||||||
|
```
|
||||||
|
|
||||||
|
Which leads visually from, by default markdown standards:
|
||||||
|
|
||||||
|
> {漢字|かんじ}
|
||||||
|
>
|
||||||
|
> {漢字|かん|じ}
|
||||||
|
|
||||||
|
to common HTML ruby syntax:
|
||||||
|
|
||||||
|
> <ruby>漢字<rt>かんじ</rt></ruby>
|
||||||
|
>
|
||||||
|
> <ruby>漢<rt>かん</rt>字<rt>じ</rt></ruby>
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
This has been made for my personal use, which is only kanjis with kanas as furigana. The regexp used do not recognize other inputs. But you can modify them easily for your use if needed.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Usage: `python3 convert-furigana.py [root folder]`
|
||||||
|
|
||||||
|
Note: Please be careful, this software applies modifications recursively!
|
6
custom/convert-furigana/examples/furigana1.md
Normal file
6
custom/convert-furigana/examples/furigana1.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{僕|ボク}の{筆記|ひっ|き}
|
||||||
|
|
||||||
|
### ~によるN
|
||||||
|
|
||||||
|
* テレビによる{報道|ほうどう}
|
||||||
|
* この{地震|じ|しん}による{津波|つ|なみ}の{心配|しんぱい}はありません。
|
7
custom/convert-furigana/examples/subfolder/furigana2.md
Normal file
7
custom/convert-furigana/examples/subfolder/furigana2.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
## ふりがなテスト
|
||||||
|
|
||||||
|
{漢字|かんじ}
|
||||||
|
|
||||||
|
{漢字|かん|じ}
|
||||||
|
|
||||||
|
{漢字|カン|ジ}
|
71
custom/convert-furigana/program/convert-furigana.py
Normal file
71
custom/convert-furigana/program/convert-furigana.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from glob import glob
|
||||||
|
import re
|
||||||
|
|
||||||
|
### Patterns ###
|
||||||
|
|
||||||
|
# https://www.reddit.com/r/learnpython/comments/h0tsaa/regex_expression_for_japanese_extracting/
|
||||||
|
re_brace = '{(.+?)}'
|
||||||
|
re_kanji = '([㐀-䶵一-鿋豈-頻]+)'
|
||||||
|
re_kana = '([ぁ-ゟ゠-ヿ]+)'
|
||||||
|
|
||||||
|
### Open file ###
|
||||||
|
|
||||||
|
def open_file(filename):
|
||||||
|
with open(filename, 'r', encoding='utf-8-sig') as file:
|
||||||
|
filedata = file.read()
|
||||||
|
return filedata
|
||||||
|
|
||||||
|
### Replace ###
|
||||||
|
|
||||||
|
def write_ruby_simple(kanji, kana):
|
||||||
|
return f"<ruby>{kanji}<rt>{kana}</rt></ruby>"
|
||||||
|
|
||||||
|
def write_ruby_multiple(kanji, kanas):
|
||||||
|
result = f"<ruby>"
|
||||||
|
for idx, kana in enumerate(kanas):
|
||||||
|
result += f"{kanji[idx]}"
|
||||||
|
result += f"<rt>{kana}</rt>"
|
||||||
|
result += f"</ruby>"
|
||||||
|
return result
|
||||||
|
|
||||||
|
def convert_to_ruby(content):
|
||||||
|
kanji = re.search(re_kanji, content.group())
|
||||||
|
kana = re.findall(re_kana, content.group())
|
||||||
|
|
||||||
|
if (len(kana) == 1):
|
||||||
|
return write_ruby_simple(kanji.group(), kana[0])
|
||||||
|
else:
|
||||||
|
return write_ruby_multiple(kanji.group(), kana)
|
||||||
|
|
||||||
|
def convert_pattern(text):
|
||||||
|
res_text = re.sub(re_brace, convert_to_ruby, text)
|
||||||
|
return res_text
|
||||||
|
|
||||||
|
### Write to file ###
|
||||||
|
|
||||||
|
def write_file(filename, text):
|
||||||
|
with open(filename, 'w', encoding='utf-8-sig') as file:
|
||||||
|
file.write(text)
|
||||||
|
|
||||||
|
|
||||||
|
### Execution ###
|
||||||
|
|
||||||
|
file_list = []
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
path = sys.argv[1]
|
||||||
|
for filename in glob(path + "/**/*.md", recursive=True):
|
||||||
|
if (os.path.isfile(filename)):
|
||||||
|
file_list.append(filename)
|
||||||
|
else:
|
||||||
|
print(f"Usage: python3 {sys.argv[0]} [root folder]")
|
||||||
|
print(f"Note: Please be careful, this software applies modifications recursively!")
|
||||||
|
|
||||||
|
for filename in file_list:
|
||||||
|
print(f"Found file {filename}, processing...", end='')
|
||||||
|
data = open_file(filename)
|
||||||
|
text = convert_pattern(data)
|
||||||
|
write_file(filename, text)
|
||||||
|
print(f" done!")
|
9
custom/convert-usage/LICENSE
Normal file
9
custom/convert-usage/LICENSE
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 keb
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
11
custom/convert-usage/README.md
Normal file
11
custom/convert-usage/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# convert-usage
|
||||||
|
|
||||||
|
## Obsidian snippet
|
||||||
|
|
||||||
|
For my Japanese Grammar (JPG) project, I have created a style for explanation on the usage of certain grammar points. There is no simple way to make it in Markdown, so I tried to make it with the least amount of HTML possible. You can find it in `examples/sample.md`. However, for it to work, you have to import a custom [CSS snippet](https://help.obsidian.md/Extending+Obsidian/CSS+snippets) to Obsidian, which is located in `obsidian-snippet/usage.css`. But using it, you will have this kind of result:
|
||||||
|
|
||||||
|
![Obsidian screenshot](./screenshot.png)
|
||||||
|
|
||||||
|
## convert-usage.py
|
||||||
|
|
||||||
|
In my Quartz rendering of my markdown data, I want this kind of data to be in a callout. However, it is not possible to combine HTML and Markdown in Obsidian. For that purpose, this script encapsulates it directly in HTML. To make it both compatible in Obsidian and Quartz, and to be still easy to write, it's done with this python script. This is probably super specific and will not be of use for anybody except me!
|
33
custom/convert-usage/examples/sample.md
Normal file
33
custom/convert-usage/examples/sample.md
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# test file
|
||||||
|
|
||||||
|
## Lorem ipsum
|
||||||
|
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris massa eros, feugiat eu dapibus nec, fermentum vel ex. Nulla malesuada luctus pretium. Phasellus ac felis ut nisi lacinia malesuada nec vel odio. Donec tincidunt tincidunt lorem vel tempus. Nullam sed efficitur ligula, a porttitor nibh. Praesent justo dui, venenatis ac mi non, laoreet consequat libero. Aenean ut molestie mauris. Proin mattis volutpat ligula eget tincidunt. Fusce ex eros, condimentum consectetur efficitur vitae, euismod at justo.
|
||||||
|
|
||||||
|
**Usage**
|
||||||
|
|
||||||
|
<div class="usage">
|
||||||
|
<div class="left">
|
||||||
|
<p><span class="box">item1</span></p>
|
||||||
|
<p><span class="box">item2</span></p>
|
||||||
|
<p><span class="box">item3</span></p>
|
||||||
|
<p><span class="box">item4</span></p>
|
||||||
|
</div>
|
||||||
|
<p class="right">+ final</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Phasellus tristique
|
||||||
|
|
||||||
|
Phasellus tristique rutrum enim. Integer vitae ex at turpis convallis posuere nec nec erat. Cras finibus erat mauris. Suspendisse id diam at sapien luctus faucibus. Pellentesque fermentum auctor libero, ut porta orci porttitor quis. In varius at sem sed ultricies. Mauris iaculis convallis erat, congue tincidunt turpis luctus vitae.
|
||||||
|
|
||||||
|
**Usage**
|
||||||
|
|
||||||
|
<div class="usage">
|
||||||
|
<div class="left">
|
||||||
|
<p><span class="box">アイテム1</span></p>
|
||||||
|
<p><span class="box">アイテム2</span></p>
|
||||||
|
<p><span class="box">アイテム3</span></p>
|
||||||
|
<p><span class="box">アイテム4</span></p>
|
||||||
|
</div>
|
||||||
|
<p class="right">+ ファイナル</p>
|
||||||
|
</div>
|
35
custom/convert-usage/obsidian-snippets/usage.css
Normal file
35
custom/convert-usage/obsidian-snippets/usage.css
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
.box {
|
||||||
|
display: inline-block;
|
||||||
|
width: fit-content;
|
||||||
|
margin: 0.2rem;
|
||||||
|
padding: 0.2rem 0.3rem 0.2rem 0.3rem;
|
||||||
|
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.usage {
|
||||||
|
display:flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.left {
|
||||||
|
padding-right: 1.7rem;
|
||||||
|
|
||||||
|
background-image: linear-gradient(black, black), linear-gradient(black, black);
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-size: 8px 2px;
|
||||||
|
background-position: top right, bottom right;
|
||||||
|
|
||||||
|
border-right: solid black;
|
||||||
|
border-width: 0 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.left p {
|
||||||
|
margin:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right {
|
||||||
|
padding-left: 1rem;
|
||||||
|
}
|
64
custom/convert-usage/program/convert-usage.py
Normal file
64
custom/convert-usage/program/convert-usage.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from glob import glob
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import re
|
||||||
|
|
||||||
|
### Patterns ###
|
||||||
|
|
||||||
|
re_usage = r'(^\*\*Usage\*\*$\n\n)'
|
||||||
|
callout_title_html = '''
|
||||||
|
<div class="callout-title">
|
||||||
|
<div class="callout-icon"></div>
|
||||||
|
<div class="callout-title-inner"><p>Usage</p></div>
|
||||||
|
</div>'''
|
||||||
|
|
||||||
|
### Open file ###
|
||||||
|
|
||||||
|
def open_file(filename):
|
||||||
|
with open(filename, 'r', encoding='utf-8-sig') as file:
|
||||||
|
filedata = file.read()
|
||||||
|
return filedata
|
||||||
|
|
||||||
|
### Write to file ###
|
||||||
|
|
||||||
|
def write_file(filename, text):
|
||||||
|
with open(filename, 'w', encoding='utf-8-sig') as file:
|
||||||
|
file.write(text)
|
||||||
|
|
||||||
|
### Replace ###
|
||||||
|
|
||||||
|
def convert_pattern(text):
|
||||||
|
text = re.sub(re_usage, '', text, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(text, features="html.parser")
|
||||||
|
|
||||||
|
for tag in soup.find_all('div', {"class": "usage"}):
|
||||||
|
new_blockquote = soup.new_tag("blockquote", **{"class": "callout notes", "data-callout": "notes"})
|
||||||
|
tag.wrap(new_blockquote)
|
||||||
|
|
||||||
|
calloutTitle = BeautifulSoup(callout_title_html, features="html.parser")
|
||||||
|
tag.insert_before(calloutTitle)
|
||||||
|
|
||||||
|
return str(soup)
|
||||||
|
|
||||||
|
|
||||||
|
### Execution ###
|
||||||
|
|
||||||
|
file_list = []
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
path = sys.argv[1]
|
||||||
|
for filename in glob(path + "/**/*.md", recursive=True):
|
||||||
|
if (os.path.isfile(filename)):
|
||||||
|
file_list.append(filename)
|
||||||
|
else:
|
||||||
|
print(f"Usage: python3 {sys.argv[0]} [root folder]")
|
||||||
|
print(f"Note: Please be careful, this software applies modifications recursively!")
|
||||||
|
|
||||||
|
for filename in file_list:
|
||||||
|
print(f"Found file {filename}, processing...", end='')
|
||||||
|
data = open_file(filename)
|
||||||
|
text = convert_pattern(data)
|
||||||
|
write_file(filename, text)
|
||||||
|
print(f" done!")
|
BIN
custom/convert-usage/screenshot.png
Normal file
BIN
custom/convert-usage/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
@ -8,7 +8,7 @@ services:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
container_name: quartz
|
container_name: quartz-jpg-container
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 8080:8080
|
||||||
|
5
custom/update-repos.sh
Normal file
5
custom/update-repos.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
git fetch convert-furigana main
|
||||||
|
git subtree pull --prefix custom/convert-furigana convert-furigana main --squash
|
||||||
|
|
||||||
|
git fetch convert-usage main
|
||||||
|
git subtree pull --prefix custom/convert-usage convert-usage main --squash
|
Loading…
Reference in New Issue
Block a user