Skip to content

Commit 49831a7

Browse files
authored
Merge pull request #59 from WSOFT-Project/develop
Lantana 2.10.1
2 parents a6a21f8 + d471a1a commit 49831a7

15 files changed

+276
-12
lines changed

.github/workflows/publish.yml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ jobs:
2828
run: |
2929
python3 setup.py sdist --formats=zip
3030
- name: Publish a Python distribution to PyPI
31-
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
3231
uses: pypa/gh-action-pypi-publish@master
3332
with:
3433
user: __token__

.vscode/tasks.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Extension build and install",
8+
"type": "shell",
9+
"command": "pip3 install -e . --break-system-packages"
10+
},
11+
{
12+
"label": "Starting serve website",
13+
"type": "shell",
14+
"command": "mkdocs serve --dev-addr localhost:8000 --watch-theme"
15+
},
16+
{
17+
"label": "Build and serve",
18+
"type": "shell",
19+
"command": "echo building",
20+
"dependsOrder": "sequence",
21+
"dependsOn": [
22+
"Extension build and install",
23+
"Starting serve website"
24+
],
25+
"problemMatcher": [],
26+
"group": {
27+
"kind" : "build",
28+
"isDefault" : true
29+
}
30+
}
31+
]
32+
}

__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__copyright__ = 'Copyright (C) 2022 WSOFT.'
2-
__version__ = '2.9.8.1'
2+
__version__ = '2.10.1'
33
__license__ = 'MIT'
44
__author__ = 'WSOFT'
55
__author_email__ = 'info@wsoft.ws'

docs/extensions/alerts2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ summary : この記事では、Alerts2拡張機能の使用方法について説
55
date : 2024-05-06
66
---
77

8-
<span class="badge bg-primary">対応バージョン:>=2.9.8.1</span>
8+
<span class="badge bg-primary">対応バージョン:>=2.10.1</span>
99

1010
Alerts2拡張機能は、Lantanaに引用を使用したアラートを追加する拡張機能です。
1111

docs/extensions/mtables.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title : MetaTables
3+
long_title : MetaTables拡張機能
4+
summary : この記事では、MetaTables拡張機能の使用方法について説明します
5+
date : 2024-07-12
6+
---
7+
8+
<span class="badge bg-primary">対応バージョン:>=2.10</span>
9+
10+
MetaTables拡張機能は、Cards拡張機能のようにLantanaに指定ディレクトリの記事一覧を生成する拡張機能です。
11+
この拡張機能を有効化することで、以下のコンポーネントが使用できるようになります。
12+
13+
- MetaTablesコンポーネント
14+
15+
### 使用方法
16+
以下の構文で使用できます。
17+
ディレクトリ名は`docs`ディレクトリからの相対パスを使用します。
18+
19+
!!!note "エスケープ解除"
20+
以下の例ではすべてエスケープのためのバックスラッシュ(`\`)が入っています。
21+
これは、この拡張機能がコードブロック中でも作用するためです。
22+
実際に使用する際はバックスラッシュ文字を削除してください。
23+
24+
```md title="index.md"
25+
=!\"ディレクトリ名"|[タイプ名,オプション(カンマ区切り)]\!=
26+
27+
**例1**
28+
29+
=!\"extensions"\|[note]!=
30+
31+
**例2**
32+
33+
=!\"extensions"\|[note,include_subdir]!=
34+
```
35+
36+
この時、記事には以下のメタデータを設定しておく必要があります。
37+
38+
```txt title="メタデータ"
39+
mt_type: タイプ
40+
```
41+
42+
#### オプション
43+
MetaTables構文中で使用できるオプションは以下の通りです。
44+
45+
オプション|説明
46+
---|---
47+
`include-index`|ディレクトリ内の`index.md`ファイルを一覧に含めます
48+
`include-subdir`|ディレクトリ内のサブディレクトリの`index.md`ファイルを一覧に含めます
49+
`style-lite`|一覧を表形式ではなく箇条書きとして出力します
50+
`smart-jump`|リンクを`title`で指定された要素にジャンプするように構成します
51+
52+
### 導入方法
53+
設定ファイル(`mkdocs.yml`)に以下の行を追加します。
54+
55+
```yml title="mkdocs.yml"
56+
markdown_extensions:
57+
(中略)
58+
- lantana.mtables
59+
(中略)
60+
```

docs/extensions/selector.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ summary : この記事では、Selector拡張機能の使用方法について
55
date : 2024-05-06
66
---
77

8-
<span class="badge bg-primary">対応バージョン:>=2.9.8.1</span>
8+
<span class="badge bg-primary">対応バージョン:>=2.10.1</span>
99

1010
Selector拡張機能は、Lantanaに選択可能なサイトへのリンクを追加する拡張機能です。
1111

lantana/after_nav_tool.html

Whitespace-only changes.

lantana/base.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
<meta http-equiv="x-ua-compatible" content="ie=edge">
99
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
1010

11-
11+
{% if not config.disable_darkmode %}
1212
<meta name="color-scheme" content="light dark">
1313
<meta name="theme-color" content="#111111" media="(prefers-color-scheme: light)">
1414
<meta name="theme-color" content="#eeeeee" media="(prefers-color-scheme: dark)">
15+
<link rel="stylesheet" href="{{ "css/bootstrap.min.css"|url }}">
16+
{% else %}
17+
<link rel="stylesheet" href="{{ "css/bootstrap-lite.min.css"|url }}">
18+
{% endif %}
1519

1620
{% if page and page.meta.language %}
1721
<meta http-equiv="content-language" content="{{ page.meta.language }}">
@@ -36,7 +40,7 @@
3640
{% endif %}
3741

3842
{% if page and page.meta and page.meta.long_title %}
39-
<title>{% if page.meta.long_title %}{{ page.title }} | {% endif %}{% if config.site_short_name %}{{ config.site_short_name }}{% else %}{{ config.site_name }}{% endif %}</title>
43+
<title>{{ page.meta.long_title }} | {% if config.site_short_name %}{{ config.site_short_name }}{% else %}{{ config.site_name }}{% endif %}</title>
4044
{% else %}
4145
<title>{% if page.title %}{{ page.title }} | {% endif %}{% if config.site_short_name %}{{ config.site_short_name }}{% else %}{{ config.site_name }}{% endif %}</title>
4246
{% endif %}
@@ -45,7 +49,6 @@
4549
<link rel="favicon" href="{{ config.favicon|url }}">
4650
{% endif %}
4751

48-
<link rel="stylesheet" href="{{ "css/bootstrap.min.css"|url }}">
4952
<link rel="stylesheet" href="{{ "css/bootstrap-icons.min.css"|url }}">
5053
<link rel="stylesheet" href="{{ "css/default.min.css"|url }}">
5154
<link rel="stylesheet" href="{{ "css/vs.min.css"|url }}">

lantana/css/bootstrap-lite.min.css

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lantana/extensions/mtables.py

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# MetaTable 拡張機能
2+
from markdown import Extension
3+
from markdown.postprocessors import Postprocessor
4+
import re
5+
import os
6+
import glob
7+
from natsort import natsorted
8+
9+
class MetaTablesExtension(Extension):
10+
def extendMarkdown(self, md, md_globals):
11+
md.postprocessors.add('mtables', MetaTablesPostprocesser(self), '>raw_html')
12+
13+
class Card:
14+
title=""
15+
content_dir=""
16+
summary=""
17+
date=""
18+
author=""
19+
dir_title=""
20+
order=""
21+
22+
COL_NUM = 3
23+
24+
def get_thumbnail_element(dir, options, index_filename='index.md',pages_filename='.pages'):
25+
dir_title=read_property(f'docs/{dir}/{pages_filename}','title')
26+
filenames = natsorted(glob.glob(f'docs/{dir}/*.md'))
27+
contain_index = "include-index" in options
28+
contain_subdir = "include-subdir" in options
29+
meta_type = options[0]
30+
style_lite = "style-lite" in options
31+
smart_jump = "smart-jump" in options
32+
cards=list()
33+
for i, filename in enumerate(filenames):
34+
if read_property(filename, 'mt_type') == meta_type:
35+
overloads = count_property(filename, 'mt_title')
36+
if overloads <= 0:
37+
overloads = 1
38+
for k in range(overloads):
39+
card=Card()
40+
card.title = read_property(filename,'mt_title', read_property(filename, 'title'), k)
41+
card.summary = read_property(filename,'mt_summary', read_property(filename, 'summary'), k)
42+
card.date = read_property(filename,'mt_date', read_property(filename, 'date'), k)
43+
card.order = read_property(filename,'mt_order', read_property(filename, 'order'), k)
44+
card.content_dir = remove_filename(filename)
45+
card.dir_title=dir_title
46+
if smart_jump:
47+
card.content_dir += f'#{convert_to_id(card.title)}'
48+
if not filename.endswith(index_filename):
49+
cards.append(card)
50+
elif contain_index:
51+
card.order = -1
52+
cards.insert(0,card)
53+
54+
# 指定されている場合はサブディレクトリも見る
55+
if contain_subdir:
56+
filenames = natsorted(glob.glob(f'docs/{dir}/*/index.md'))
57+
for i, filename in enumerate(filenames):
58+
if read_property(filename, 'mt_type') == meta_type:
59+
overloads = count_property(filename, 'mt_title')
60+
if overloads <= 0:
61+
overloads = 1
62+
for k in range(overloads):
63+
card=Card()
64+
card.title = read_property(filename,'mt_title', read_property(filename, 'title'), k)
65+
card.summary = read_property(filename,'mt_summary', read_property(filename, 'summary'), k)
66+
card.date = read_property(filename,'mt_date', read_property(filename, 'date'), k)
67+
card.order = read_property(filename,'mt_order', read_property(filename, 'order'), k)
68+
card.content_dir = remove_filename(filename)
69+
card.dir_title=dir_title
70+
cards.append(card)
71+
72+
if smart_jump:
73+
card.content_dir += f'#{convert_to_id(card.title)}'
74+
75+
cards = natsorted(cards,key=lambda x:x.order)
76+
77+
if style_lite:
78+
html = '<ul>'
79+
80+
for card in cards:
81+
html += f'<li><a href="/{card.content_dir}/">{card.title}</a></li>'
82+
83+
html += '</ul>'
84+
else:
85+
html = '<table class="table"><thead><th></th><th></th></thead><tbody>\n'
86+
for card in cards:
87+
html += '<tr>\n'
88+
html += f'<td><a href="/{card.content_dir}">{card.title}{card.order}</a></td>'
89+
html += f'<td>{card.summary}</td>'
90+
html += '</tr>'
91+
html += '</tbody></table>'
92+
return html
93+
94+
def convert_to_id(name) -> str:
95+
name = name.lower()
96+
name = name.replace(' ', '-')
97+
name = name.replace('(', '')
98+
name = name.replace(')', '')
99+
name = name.replace(',', '')
100+
return name
101+
102+
def remove_filename(filename):
103+
"""
104+
docs/***.mdのようなファイル名を**のみに切り出す関数
105+
"""
106+
filename = filename.replace("docs/","",1)
107+
filename=filename[::-1].replace("dm.","",1)
108+
return filename[::-1]
109+
110+
def count_property(filename,key):
111+
"""記事や.pagesファイルにプロパティがいくつあるかを調べる関数
112+
113+
filename=ファイル名、key=プロパティの名前
114+
"""
115+
with open(filename, "r", encoding="utf-8") as f:
116+
search=re.findall(key+'\ *:\ *(.+)*\n*', f.read())
117+
if search != None:
118+
return len(search)
119+
else:
120+
return 0
121+
122+
123+
def read_property(filename,key,default="",index=0):
124+
"""記事や.pagesファイルからプロパティを読みだす関数
125+
126+
filename=ファイル名、key=プロパティの名前
127+
"""
128+
with open(filename, "r", encoding="utf-8") as f:
129+
search=re.findall(key+'\ *:\ *(.+)*\n*', f.read())
130+
if search != None and len(search) > 0:
131+
if len(search) > index:
132+
return search[index]
133+
else:
134+
return search[index]
135+
else:
136+
return default
137+
138+
139+
class MetaTablesPostprocesser(Postprocessor):
140+
_pattern = re.compile("=\!\\\"(.*)\\\"(\\|\\[(.*)\\])?\!=")
141+
#_pattern = re.compile(r"\[WS[0-9]{5}\]")
142+
def run(self, html):
143+
html = re.sub(self._pattern, self._replace_card, html)
144+
return html
145+
146+
def _replace_card(self, match):
147+
return get_thumbnail_element(match.group(1),(match.group(3) or "").split(','))
148+
149+
150+
151+
def makeExtension(*args, **kwargs):
152+
return CardsExtension(*args, **kwargs)
153+

lantana/main.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ <h1>{{ page.title }}</h1>
5151
{% endif %}
5252
{% if page and not page.meta.disable_tools %}
5353
<div class="d-flex justify-content-between">
54+
{% if page and not page.meta.disable_nav_tool %}
5455
<div>
5556
{% if page.previous_page %}
5657
<a class="btn text-primary print-hide" href="{{ page.previous_page.url|url }}" title="{{ page.previous_page.title }}"><i class="bi bi-chevron-left"></i></a>
@@ -63,15 +64,17 @@ <h1>{{ page.title }}</h1>
6364
<a class="btn text-muted print-hide"><i class="bi bi-chevron-right"></i></a>
6465
{% endif %}
6566
</div>
67+
{% endif %}
68+
{% include "after_nav_tool.html" %}
6669
<div>
6770
<div>
6871
{% if page and page.meta.author %}
6972
{% if page and page.meta.author_url %}
7073
<a href="{{ page.meta.author_url }}" class="unnewtab">{{ page.meta.author }}</a>
7174
{% else %}
7275
<span>{{ page.meta.author }}</span>
73-
{% endif %}
7476
<span>|</span>
77+
{% endif %}
7578
{% else %}
7679
{% if git_page_authors %}
7780
<small>{{ git_page_authors | default('enable mkdocs-git-authors-plugin') }}</small>
@@ -95,6 +98,7 @@ <h1>{{ page.title }}</h1>
9598
{% else %}
9699
<a class="btn disabled print-hide"><i class="bi bi-pencil"></i></a>
97100
{% endif %}
101+
{% endif %}
98102
<span class="dropdown print-hide">
99103
<button class="btn" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi bi-share"></i></button>
100104
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
@@ -106,7 +110,6 @@ <h1>{{ page.title }}</h1>
106110
<li><button class="btn dropdown-item" id="page-url-copy-btn"><i class="bi bi-clipboard"></i>&nbsp;URLをコピー</button></li>
107111
</ul>
108112
</span>
109-
{% endif %}
110113
</div>
111114
</div>
112115
</div>

lantana/version.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Product" : "Lantana",
33
"CodeName" : "tapioca",
4-
"Version" : "2.9.8.1",
5-
"FullName" : "WSOFT Lantana v2.9.8.1(tapioca)"
4+
"Version" : "2.10.1",
5+
"FullName" : "WSOFT Lantana v2.10.1(tapioca)"
66
}

mkdocs.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ favicon : favicon.png
1919
image : favicon.png
2020
language : ja
2121

22+
disable_darkmode : true
23+
2224
share:
2325
twitter_params : '&via=WSOFT7&related=WSOFT7&hashtags=WSOFTDocs'
2426

@@ -51,6 +53,7 @@ markdown_extensions:
5153
- lantana.selector
5254
- attr_list
5355
- lantana.cards
56+
- lantana.mtables
5457
- mdx_wsid
5558
- footnotes
5659
- pymdownx.highlight:

0 commit comments

Comments
 (0)