Skip to content

Commit 7bb8a95

Browse files
committed
Redo "内部リンクを相対リンクで生成する機能 with settings.USE_RELATIVE_LINK = True"
This reverts commit e4597df, which was actually the reverse commit for the change 61156b4 made to af55908.
1 parent 6dd1cca commit 7bb8a95

File tree

14 files changed

+103
-33
lines changed

14 files changed

+103
-33
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
*.pyc
22
cpprefjp/site/
3+
cpprefjp/image/
34
cpprefjp/cpprefjp.github.io/
5+
cpprefjp/cpprefjp.relative/
46
boostjp/site/
7+
boostjp/image/
58
boostjp/boostjp.github.io/
9+
boostjp/boostjp.relative/
610
settings.*.cache
711

812
/crsearch.json/crsearch.json
13+
/crsearch.json/crsearch.js
914
/cpprefjp/static/static/kunai
1015
/cpprefjp/static/static/crsearch/*
1116

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ $ git submodule update -i
2424

2525
```bash
2626
git clone https://github.com/cpprefjp/site.git cpprefjp/site
27+
git clone https://github.com/cpprefjp/image.git cpprefjp/image
2728

2829
# kunai 用のデータを生成する
2930
git clone https://github.com/cpprefjp/kunai.git
@@ -45,6 +46,7 @@ popd
4546
mkdir -p cpprefjp/static/static/crsearch
4647
pushd cpprefjp/static/static/crsearch
4748
ln -s ../../../../crsearch.json/crsearch.json crsearch.json
49+
ln -s ../../../../crsearch.json/crsearch.js crsearch.js # Optional (ローカル file:///... で閲覧する場合に必要)
4850
popd
4951

5052
# site_generator 用の docker イメージを生成する
@@ -56,6 +58,7 @@ popd
5658
```bash
5759
# この辺は必要に応じて実行する
5860
(cd cpprefjp/site && git pull)
61+
(cd cpprefjp/image && git pull)
5962
./crsearch.json/docker.sh run
6063
./kunai/docker.sh run build
6164

@@ -74,6 +77,7 @@ http://localhost:8000 を開けば `index.html` が表示されます。
7477

7578
```bash
7679
git clone https://github.com/boostjp/site.git boostjp/site
80+
git clone https://github.com/boostjp/image.git boostjp/image
7781

7882
# site_generator 用の docker イメージを生成する
7983
./docker.sh build

boostjp/templates/base.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626

2727
{% block rss %}{% endblock %}
2828

29-
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
30-
<link rel="stylesheet" href="/static/pygments/default.css">
31-
<!-- <link rel="stylesheet" href="/static/css/root.css"> -->
29+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
30+
<link rel="stylesheet" href="{{ relative_base }}/static/pygments/default.css">
31+
<!-- <link rel="stylesheet" href="{{ relative_base }}/static/css/root.css"> -->
3232

33-
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
34-
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
35-
<!-- <script src="//platform.twitter.com/widgets.js"></script> -->
33+
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
34+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
35+
<!-- <script src="https://platform.twitter.com/widgets.js"></script> -->
3636

37-
<!-- <script src="/static/js/root.js"></script> -->
37+
<!-- <script src="{{ relative_base }}/static/js/root.js"></script> -->
3838

3939
{% block mathjax %}{% endblock %}
4040

@@ -254,7 +254,7 @@
254254
<span class="icon-bar"></span>
255255
<span class="icon-bar"></span>
256256
</button>
257-
<a class="navbar-brand" href="/">
257+
<a class="navbar-brand" href="{{ relative_index }}">
258258
<div class="title-wrapper clearfix">
259259
<div class="title">{% block brand %}{% endblock %}</div>
260260
</div>
@@ -326,7 +326,7 @@
326326
</body>
327327
<!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6. chromium.org/developers/how-tos/chrome-frame-getting-started -->
328328
<!--[if lt IE 7 ]>
329-
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
329+
<script src="https://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
330330
<script>
331331
window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})
332332
</script>

boostjp/templates/content.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<li {{ 'style="display: none"' if not parent_opened }} class="parent_li {{ 'active' if child.opened }}">
1616
<span class="treespan" onclick="tree_onclick.call(this, event)"><i class="glyphicon {{ 'glyphicon-minus' if child.opened else 'glyphicon-plus' }}"></i></span>
1717
{% if child.href %}
18-
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
18+
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
1919
{% else %}
2020
{{ child.title|e }}{{ child.encoded_cpp_meta }}
2121
{% endif %}
@@ -26,7 +26,7 @@
2626
{% else %}
2727
<li {{ 'style="display: none"' if not parent_opened }}>
2828
{% if child.href %}
29-
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
29+
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
3030
{% else %}
3131
{{ child.title|e }}{{ child.encoded_cpp_meta }}
3232
{% endif %}
@@ -49,7 +49,7 @@
4949
<li {{ 'class="active"' if header.is_active }} itemscope itemtype="http://www.schema.org/SiteNavigationElement">
5050
<span>
5151
{% if not header.is_active and header.href %}
52-
<a href="{{ header.href }}" itemprop="url">
52+
<a href="{{ relative_base }}{{ header.href }}" itemprop="url">
5353
{% if loop.index == 1 %}
5454
<i class="glyphicon glyphicon-home"></i>
5555
{% else %}

cpprefjp/ghwebhook_on_user.sh

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ cp crsearch.json/crsearch.json cpprefjp/static/static/crsearch/
6060
# サイト生成
6161
clone_and_fallback cpprefjp/cpprefjp.github.io [email protected]:cpprefjp/cpprefjp.github.io.git
6262
clone_and_fallback cpprefjp/site [email protected]:cpprefjp/site.git
63+
clone_and_fallback cpprefjp/image [email protected]:cpprefjp/image.git
6364
./docker.sh build
6465
./docker.sh run settings.cpprefjp "$@"
6566

cpprefjp/templates/base.html

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@
2222

2323
{% block rss %}{% endblock %}
2424

25-
<link rel="apple-touch-icon" sizes="180x180" href="/static/favicons/apple-touch-icon.png{{ cachebust }}">
26-
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicons/favicon-32x32.png{{ cachebust }}">
27-
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicons/favicon-16x16.png{{ cachebust }}">
28-
<link rel="manifest" href="/static/favicons/manifest.json{{ cachebust }}">
25+
<link rel="apple-touch-icon" sizes="180x180" href="{{ relative_base }}/static/favicons/apple-touch-icon.png{{ cachebust }}">
26+
<link rel="icon" type="image/png" sizes="32x32" href="{{ relative_base }}/static/favicons/favicon-32x32.png{{ cachebust }}">
27+
<link rel="icon" type="image/png" sizes="16x16" href="{{ relative_base }}/static/favicons/favicon-16x16.png{{ cachebust }}">
28+
<link rel="manifest" href="{{ relative_base }}/manifest.json{{ cachebust }}">
2929
<meta name="theme-color" content="#f5f8fc">
3030

31-
<link rel="stylesheet" href="/static/pygments/default.css{{ cachebust }}">
32-
<!-- <link rel="stylesheet" href="/static/css/root.css"> -->
31+
<link rel="stylesheet" href="{{ relative_base }}/static/pygments/default.css{{ cachebust }}">
32+
<!-- <link rel="stylesheet" href="{{ relative_base }}/static/css/root.css"> -->
3333

3434
{% block mathjax %}{% endblock %}
3535

36-
<link href="/static/kunai/css/kunai-stage-0.css{{ cachebust }}" rel="stylesheet">
37-
<link href="/static/kunai/css/kunai-stage-1.css{{ cachebust }}" rel="stylesheet">
38-
<link href="/static/kunai/css/kunai-stage-2.css{{ cachebust }}" rel="stylesheet">
39-
<link href="/static/kunai/css/kunai-stage-3.css{{ cachebust }}" rel="stylesheet">
36+
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-0.css{{ cachebust }}" rel="stylesheet">
37+
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-1.css{{ cachebust }}" rel="stylesheet">
38+
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-2.css{{ cachebust }}" rel="stylesheet">
39+
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-3.css{{ cachebust }}" rel="stylesheet">
4040

41-
<script type="text/javascript" src="/static/kunai/js/kunai-vendor.js{{ cachebust }}"></script>
42-
<script type="text/javascript" src="/static/kunai/js/kunai.js{{ cachebust }}"></script>
41+
<script type="text/javascript" src="{{ relative_base }}/static/kunai/js/kunai-vendor.js{{ cachebust }}"></script>
42+
<script type="text/javascript" src="{{ relative_base }}/static/kunai/js/kunai.js{{ cachebust }}"></script>
4343

4444
<script type="text/javascript">
4545
document.addEventListener('DOMContentLoaded', function() {
@@ -60,7 +60,7 @@
6060
<span class="icon-bar"></span>
6161
<span class="icon-bar"></span>
6262
</button>
63-
<a class="navbar-brand" href="/">
63+
<a class="navbar-brand" href="{{ relative_index }}">
6464
<div class="title-wrapper clearfix">
6565
<div class="title">{% block brand %}{% endblock %}</div>
6666
</div>

cpprefjp/templates/content.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<li class="parent_li {{ 'active' if child.opened }}">
1818
<span class="treespan"></span>
1919
{% if child.href %}
20-
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
20+
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
2121
{% else %}
2222
{{ child.title|e }}{{ child.encoded_cpp_meta }}
2323
{% endif %}
@@ -28,7 +28,7 @@
2828
{% else %}
2929
<li>
3030
{% if child.href %}
31-
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
31+
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
3232
{% else %}
3333
{{ child.title|e }}{{ child.encoded_cpp_meta }}
3434
{% endif %}
@@ -58,7 +58,7 @@
5858
<li {{ 'class="active"' if header.is_active }} itemscope itemtype="http://www.schema.org/SiteNavigationElement">
5959
<span>
6060
{% if not header.is_active and header.href %}
61-
<a href="{{ header.href }}" itemprop="url">
61+
<a href="{{ relative_base }}{{ header.href }}" itemprop="url">
6262
{% if loop.index == 1 %}
6363
<i class="fa fa-fw fa-home"></i>
6464
{% else %}

crsearch.json/run.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,11 @@ def main():
487487
paths = chain.from_iterable([get_files(d) for d in _KNOWN_DIRS])
488488
all_paths = list(get_files('site'))
489489
result = Generator().generate('site', paths, all_paths)
490+
crsearch_json = json.dumps(result, separators=(',', ':'), ensure_ascii=False, sort_keys=True)
490491
with open('crsearch.json', 'wb') as f:
491-
f.write(json.dumps(result, separators=(',', ':'), ensure_ascii=False, sort_keys=True).encode('utf-8'))
492+
f.write(crsearch_json.encode('utf-8'))
493+
with open('crsearch.js', 'wb') as f:
494+
f.write(('callback(%s)' % crsearch_json).encode('utf-8'))
492495

493496

494497
if __name__ == '__main__':

markdown_to_html

run.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import importlib
77
import json
88
import os
9+
import posixpath
910
import re
1011
import subprocess
1112
import sys
@@ -69,6 +70,9 @@ def md_to_html(md_data, path, hrefs=None, global_qualify_list=None, global_defin
6970
'base_path': '/'.join(paths[:-1]),
7071
'full_path': path + '.md',
7172
'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,
7276
}
7377
extension_configs['codehilite'] = {
7478
'noclasses': False
@@ -510,11 +514,11 @@ def convert_pageinfo(pageinfo, sidebar, sidebar_index, template, hrefs, global_q
510514
sidebar.set_active(pageinfo['paths'])
511515

512516
content_header = ContentHeader(pageinfo['paths'], sidebar, sidebar_index)
513-
convert(pageinfo['path'], template, {
517+
context = {
514518
'title': (
515519
pageinfo['title'] if pageinfo['is_index'] else
516520
pageinfo['title'] + settings.TITLE_SUFFIX),
517-
'url': settings.BASE_URL + '/' + pageinfo['href'],
521+
'url': settings.BASE_URL + pageinfo['href'],
518522
'description': pageinfo['description'],
519523
'cachebust': _CACHEBUST,
520524
'disable_sidebar': settings.DISABLE_SIDEBAR,
@@ -530,7 +534,18 @@ def convert_pageinfo(pageinfo, sidebar, sidebar_index, template, hrefs, global_q
530534
'project_name': settings.PROJECT_NAME,
531535
'latest_commit_info': latest_commit_info,
532536
'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)
534549

535550

536551
def main():
@@ -607,6 +622,13 @@ def run(pageinfos):
607622
# 静的ファイルをコピーする
608623
subprocess.call(['cp', '-v', '-RL'] + glob.glob(os.path.join(settings.STATIC_DIR, '*')) + [settings.OUTPUT_DIR])
609624

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+
610632

611633
if __name__ == '__main__':
612634
main()

settings/boostjp.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
# 静的ファイルディレクトリ
1111
STATIC_DIR = 'boostjp/static'
1212

13+
# 画像ファイルディレクトリ / GitHubリポジトリ
14+
IMAGE_DIR = 'boostjp/image'
15+
IMAGE_REPO = 'boostjp/image'
16+
1317
# 出力ディレクトリ
1418
OUTPUT_DIR = 'boostjp/boostjp.github.io'
1519

@@ -80,6 +84,7 @@
8084
# 'git' => CACHEBUST_DIR のディレクトリの git rev-parse HEAD の結果を使う
8185
CACHEBUST_TYPE = 'time'
8286

87+
USE_RELATIVE_LINK = False
8388

8489
# 並び替えルール
8590
def get_order_priority(name):

settings/boostjp_relative.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
from __future__ import print_function
5+
from __future__ import unicode_literals
6+
7+
from .boostjp import * # NOQA
8+
9+
USE_MINIFY = False
10+
11+
OUTPUT_DIR = 'boostjp/boostjp.relative'
12+
GOOGLE_ANALYTICS = ''
13+
USE_RELATIVE_LINK = True

settings/cpprefjp.py

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
# 静的ファイルディレクトリ
1111
STATIC_DIR = 'cpprefjp/static'
1212

13+
# 画像ファイルディレクトリ / GitHubリポジトリ
14+
IMAGE_DIR = 'cpprefjp/image'
15+
IMAGE_REPO = 'cpprefjp/image'
16+
1317
# 出力ディレクトリ
1418
OUTPUT_DIR = 'cpprefjp/cpprefjp.github.io'
1519

@@ -81,6 +85,8 @@
8185
CACHEBUST_TYPE = 'git'
8286
CACHEBUST_DIR = 'kunai'
8387

88+
USE_RELATIVE_LINK = False
89+
8490
# 並び替えルール
8591
ORDER_PRIORITY_LIST = [
8692
'op_constructor',

settings/cpprefjp_relative.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
from __future__ import print_function
5+
from __future__ import unicode_literals
6+
7+
from .cpprefjp import * # NOQA
8+
9+
OUTPUT_DIR = 'cpprefjp/cpprefjp.relative'
10+
GOOGLE_ANALYTICS = ''
11+
USE_RELATIVE_LINK = True

0 commit comments

Comments
 (0)