Skip to content

Commit

Permalink
USE_RELATIVE_LINK に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 29, 2022
1 parent af55908 commit 9651af9
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*.pyc
cpprefjp/site/
cpprefjp/cpprefjp.github.io/
cpprefjp/cpprefjp.relative/
boostjp/site/
boostjp/boostjp.github.io/
boostjp/boostjp.relative/
settings.*.cache

/crsearch.json/crsearch.json
Expand Down
8 changes: 4 additions & 4 deletions boostjp/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
{% block rss %}{% endblock %}

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/pygments/default.css">
<!-- <link rel="stylesheet" href="/static/css/root.css"> -->
<link rel="stylesheet" href="{{ relative_base }}/static/pygments/default.css">
<!-- <link rel="stylesheet" href="{{ relative_base }}/static/css/root.css"> -->

<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<!-- <script src="//platform.twitter.com/widgets.js"></script> -->

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

{% block mathjax %}{% endblock %}

Expand Down Expand Up @@ -254,7 +254,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<a class="navbar-brand" href="{{ relative_base }}/">
<div class="title-wrapper clearfix">
<div class="title">{% block brand %}{% endblock %}</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions boostjp/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<li {{ 'style="display: none"' if not parent_opened }} class="parent_li {{ 'active' if child.opened }}">
<span class="treespan" onclick="tree_onclick.call(this, event)"><i class="glyphicon {{ 'glyphicon-minus' if child.opened else 'glyphicon-plus' }}"></i></span>
{% if child.href %}
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
{% else %}
{{ child.title|e }}{{ child.encoded_cpp_meta }}
{% endif %}
Expand All @@ -26,7 +26,7 @@
{% else %}
<li {{ 'style="display: none"' if not parent_opened }}>
{% if child.href %}
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
{% else %}
{{ child.title|e }}{{ child.encoded_cpp_meta }}
{% endif %}
Expand All @@ -49,7 +49,7 @@
<li {{ 'class="active"' if header.is_active }} itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span>
{% if not header.is_active and header.href %}
<a href="{{ header.href }}" itemprop="url">
<a href="{{ relative_base }}{{ header.href }}" itemprop="url">
{% if loop.index == 1 %}
<i class="glyphicon glyphicon-home"></i>
{% else %}
Expand Down
28 changes: 14 additions & 14 deletions cpprefjp/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@

{% block rss %}{% endblock %}

<link rel="apple-touch-icon" sizes="180x180" href="/static/favicons/apple-touch-icon.png{{ cachebust }}">
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicons/favicon-32x32.png{{ cachebust }}">
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicons/favicon-16x16.png{{ cachebust }}">
<link rel="manifest" href="/static/favicons/manifest.json{{ cachebust }}">
<link rel="mask-icon" href="/static/favicons/safari-pinned-tab.svg{{ cachebust }}" color="#f5f8fc">
<link rel="apple-touch-icon" sizes="180x180" href="{{ relative_base }}/static/favicons/apple-touch-icon.png{{ cachebust }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ relative_base }}/static/favicons/favicon-32x32.png{{ cachebust }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ relative_base }}/static/favicons/favicon-16x16.png{{ cachebust }}">
<link rel="manifest" href="{{ relative_base }}/static/favicons/manifest.json{{ cachebust }}">
<link rel="mask-icon" href="{{ relative_base }}/static/favicons/safari-pinned-tab.svg{{ cachebust }}" color="#f5f8fc">
<meta name="theme-color" content="#f5f8fc">

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

{% block mathjax %}{% endblock %}

<link href="/static/kunai/css/kunai-stage-0.css{{ cachebust }}" rel="stylesheet">
<link href="/static/kunai/css/kunai-stage-1.css{{ cachebust }}" rel="stylesheet">
<link href="/static/kunai/css/kunai-stage-2.css{{ cachebust }}" rel="stylesheet">
<link href="/static/kunai/css/kunai-stage-3.css{{ cachebust }}" rel="stylesheet">
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-0.css{{ cachebust }}" rel="stylesheet">
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-1.css{{ cachebust }}" rel="stylesheet">
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-2.css{{ cachebust }}" rel="stylesheet">
<link href="{{ relative_base }}/static/kunai/css/kunai-stage-3.css{{ cachebust }}" rel="stylesheet">

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

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
Expand All @@ -61,7 +61,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<a class="navbar-brand" href="{{ relative_base }}/">
<div class="title-wrapper clearfix">
<div class="title">{% block brand %}{% endblock %}</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions cpprefjp/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<li class="parent_li {{ 'active' if child.opened }}">
<span class="treespan"></span>
{% if child.href %}
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
{% else %}
{{ child.title|e }}{{ child.encoded_cpp_meta }}
{% endif %}
Expand All @@ -28,7 +28,7 @@
{% else %}
<li>
{% if child.href %}
<a href="{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
<a href="{{ relative_base }}{{ child.href }}">{{ child.title|e }}</a>{{ child.encoded_cpp_meta }}
{% else %}
{{ child.title|e }}{{ child.encoded_cpp_meta }}
{% endif %}
Expand Down Expand Up @@ -58,7 +58,7 @@
<li {{ 'class="active"' if header.is_active }} itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span>
{% if not header.is_active and header.href %}
<a href="{{ header.href }}" itemprop="url">
<a href="{{ relative_base }}{{ header.href }}" itemprop="url">
{% if loop.index == 1 %}
<i class="fa fa-fw fa-home"></i>
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion markdown_to_html
16 changes: 13 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import importlib
import json
import os
import posixpath
import re
import subprocess
import sys
Expand Down Expand Up @@ -69,6 +70,7 @@ def md_to_html(md_data, path, hrefs=None, global_qualify_list=None):
'base_path': '/'.join(paths[:-1]),
'full_path': path + '.md',
'extension': '.html',
'use_relative_link': settings.USE_RELATIVE_LINK,
}
extension_configs['codehilite'] = {
'noclasses': False
Expand Down Expand Up @@ -501,11 +503,11 @@ def convert_pageinfo(pageinfo, sidebar, sidebar_index, template, hrefs, global_q
sidebar.set_active(pageinfo['paths'])

content_header = ContentHeader(pageinfo['paths'], sidebar, sidebar_index)
convert(pageinfo['path'], template, {
context = {
'title': (
pageinfo['title'] if pageinfo['is_index'] else
pageinfo['title'] + settings.TITLE_SUFFIX),
'url': settings.BASE_URL + '/' + pageinfo['href'],
'url': settings.BASE_URL + pageinfo['href'],
'description': pageinfo['description'],
'cachebust': _CACHEBUST,
'disable_sidebar': settings.DISABLE_SIDEBAR,
Expand All @@ -521,7 +523,15 @@ def convert_pageinfo(pageinfo, sidebar, sidebar_index, template, hrefs, global_q
'project_name': settings.PROJECT_NAME,
'latest_commit_info': latest_commit_info,
'keywords': settings.META_KEYWORDS,
}, hrefs, global_qualify_list)
'relative_base': ''
}
if settings.USE_RELATIVE_LINK:
url_current_dir = posixpath.dirname(context['url'])
context['relative_base'] = posixpath.relpath(settings.BASE_URL, url_current_dir)
# 以下は <meta /> で埋め込む情報なので敢えて相対パスにはしない。
# context['url'] = posixpath.relpath(context['url'], url_current_dir)
# context['rss'] = posixpath.relpath(context['rss'], url_current_dir)
convert(pageinfo['path'], template, context, hrefs, global_qualify_list)


def main():
Expand Down
1 change: 1 addition & 0 deletions settings/boostjp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
# 'git' => CACHEBUST_DIR のディレクトリの git rev-parse HEAD の結果を使う
CACHEBUST_TYPE = 'time'

USE_RELATIVE_LINK = False

# 並び替えルール
def get_order_priority(name):
Expand Down
13 changes: 13 additions & 0 deletions settings/boostjp_relative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .boostjp import * # NOQA

USE_MINIFY = False

OUTPUT_DIR = 'boostjp/boostjp.relative'
GOOGLE_ANALYTICS = ''
USE_RELATIVE_LINK = True
2 changes: 2 additions & 0 deletions settings/cpprefjp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
CACHEBUST_TYPE = 'git'
CACHEBUST_DIR = 'kunai'

USE_RELATIVE_LINK = False

# 並び替えルール
ORDER_PRIORITY_LIST = [
'op_constructor',
Expand Down
11 changes: 11 additions & 0 deletions settings/cpprefjp_relative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .cpprefjp import * # NOQA

OUTPUT_DIR = 'cpprefjp/cpprefjp.relative'
GOOGLE_ANALYTICS = ''
USE_RELATIVE_LINK = True

0 comments on commit 9651af9

Please sign in to comment.