6
6
import importlib
7
7
import json
8
8
import os
9
+ import posixpath
9
10
import re
10
11
import subprocess
11
12
import sys
@@ -69,6 +70,9 @@ def md_to_html(md_data, path, hrefs=None, global_qualify_list=None, global_defin
69
70
'base_path' : '/' .join (paths [:- 1 ]),
70
71
'full_path' : path + '.md' ,
71
72
'extension' : '.html' ,
73
+ 'use_relative_link' : settings .USE_RELATIVE_LINK ,
74
+ 'image_repo' : settings .IMAGE_REPO ,
75
+ 'use_static_image' : settings .IMAGE_DIR is not None ,
72
76
}
73
77
extension_configs ['codehilite' ] = {
74
78
'noclasses' : False
@@ -510,11 +514,11 @@ def convert_pageinfo(pageinfo, sidebar, sidebar_index, template, hrefs, global_q
510
514
sidebar .set_active (pageinfo ['paths' ])
511
515
512
516
content_header = ContentHeader (pageinfo ['paths' ], sidebar , sidebar_index )
513
- convert ( pageinfo [ 'path' ], template , {
517
+ context = {
514
518
'title' : (
515
519
pageinfo ['title' ] if pageinfo ['is_index' ] else
516
520
pageinfo ['title' ] + settings .TITLE_SUFFIX ),
517
- 'url' : settings .BASE_URL + '/' + pageinfo ['href' ],
521
+ 'url' : settings .BASE_URL + pageinfo ['href' ],
518
522
'description' : pageinfo ['description' ],
519
523
'cachebust' : _CACHEBUST ,
520
524
'disable_sidebar' : settings .DISABLE_SIDEBAR ,
@@ -530,7 +534,18 @@ def convert_pageinfo(pageinfo, sidebar, sidebar_index, template, hrefs, global_q
530
534
'project_name' : settings .PROJECT_NAME ,
531
535
'latest_commit_info' : latest_commit_info ,
532
536
'keywords' : settings .META_KEYWORDS ,
533
- }, hrefs , global_qualify_list , global_defined_words )
537
+ 'relative_base' : '' ,
538
+ 'relative_index' : '/'
539
+ }
540
+ if settings .USE_RELATIVE_LINK :
541
+ url_current_dir = posixpath .dirname (context ['url' ])
542
+ context ['relative_base' ] = posixpath .relpath (settings .BASE_URL , url_current_dir )
543
+ # Note: ローカル (file:///) で閲覧時にディレクトリを開いてしまわないように "/" で終わらず "index.html"も明示する。
544
+ context ['relative_index' ] = posixpath .relpath (settings .BASE_URL , url_current_dir ) + '/index.html'
545
+ # Note: 以下は <meta /> で埋め込む情報なので敢えて相対パスにはしない。
546
+ # context['url'] = posixpath.relpath(context['url'], url_current_dir)
547
+ # context['rss'] = posixpath.relpath(context['rss'], url_current_dir)
548
+ convert (pageinfo ['path' ], template , context , hrefs , global_qualify_list , global_defined_words )
534
549
535
550
536
551
def main ():
@@ -607,6 +622,13 @@ def run(pageinfos):
607
622
# 静的ファイルをコピーする
608
623
subprocess .call (['cp' , '-v' , '-RL' ] + glob .glob (os .path .join (settings .STATIC_DIR , '*' )) + [settings .OUTPUT_DIR ])
609
624
625
+ # 画像リポジトリ (image) の画像ファイル (*.png, *.jpg, *.svg) をコピーする
626
+ if settings .IMAGE_DIR is not None :
627
+ os .system ("cd '%s' && find . -name '*.png' -or -name '*.jpg' -or -name '*.svg' | tee /dev/stderr | cpio -updmv '%s'" % (
628
+ settings .IMAGE_DIR ,
629
+ os .path .relpath (os .path .join (settings .OUTPUT_DIR , 'static/image' ), settings .IMAGE_DIR )
630
+ ))
631
+
610
632
611
633
if __name__ == '__main__' :
612
634
main ()
0 commit comments