Skip to content

Commit 18be795

Browse files
authored
Merge pull request #44 from coderdojo-japan/add-redirect-plugin
リダイレクト機能追加
2 parents 4e7cb5e + 35ee4ff commit 18be795

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ group :jekyll_plugins do
1111
gem 'jekyll-include-cache'
1212
gem 'jekyll-sitemap'
1313
gem 'jekyll-liquify'
14+
gem 'jekyll-redirect-from'
1415

1516
# No need this gem because we build by GitHub Actions and serve on Pages.
1617
# gem 'github-pages'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ GEM
104104
liquid
105105
logger
106106
redcarpet
107+
jekyll-redirect-from (0.16.0)
108+
jekyll (>= 3.3, < 5.0)
107109
jekyll-sass-converter (3.1.0)
108110
sass-embedded (~> 1.75)
109111
jekyll-sitemap (1.4.0)
@@ -218,6 +220,7 @@ DEPENDENCIES
218220
jekyll-feed
219221
jekyll-include-cache
220222
jekyll-liquify
223+
jekyll-redirect-from
221224
jekyll-sitemap
222225
mini_racer
223226
rake

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ registration: https://dojocon-japan.doorkeeper.jp/events/176163
2626
plugins:
2727
- jekyll-feed
2828
- jekyll-include-cache
29+
- jekyll-redirect-from
2930
- jekyll-sitemap # This must be LAST to include contents generated by gems above
3031
- jekyll-liquify # This enable to use variables in frontmatter
3132

_posts/2025-07-21-contest-terms.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
layout: post
33
title: DojoCon Japan 2025 プログラミングコンテスト 参加規約
44
date: 2025-07-21T00:00:00 UTC+09:00
5-
permalink: /contests/terms.html
5+
permalink: /contests/terms/
6+
redirect_from: /contests/terms.html
67
---
78
<img src="/img/common/coderdojo-nameplate.webp" loading="lazy" alt="DojoCon Japan Cover Photo"
89
title="DojoCon Japan Cover Photo" class="mb-4" />

_posts/2025-08-02-contest-how-to-apply.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ title-in-news-list: 『DojoCon Japan 2025 プログラミングコンテスト
55
date: 2025-08-02T01:00:00 UTC+09:00
66
categories: news
77
tags: 企画
8-
permalink: /contests/how-to-apply.html
8+
permalink: /contests/how-to-apply/
9+
redirect_from: /contests/how-to-apply.html
910
---
1011
<style>
1112
.bordered {

test-directory-structure.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
from html.parser import HTMLParser
23
from pathlib import Path
34

45
"""
@@ -12,6 +13,39 @@
1213
"""
1314

1415

16+
class Parser(HTMLParser):
17+
"""
18+
<meta http-equiv="refresh"> を含むファイルを検査の対象から除外する
19+
"""
20+
21+
def __init__(self, *, convert_charrefs: bool = True) -> None:
22+
super().__init__(convert_charrefs=convert_charrefs)
23+
self.is_redirect = False
24+
25+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
26+
if self.is_redirect:
27+
return
28+
29+
if tag != "meta":
30+
return
31+
32+
for attr_name, attr_value in attrs:
33+
if attr_name == "http-equiv" and attr_value == "refresh":
34+
self.is_redirect = True
35+
break
36+
37+
38+
def is_redirect(path: str) -> bool:
39+
with open(path) as fp:
40+
content = fp.read()
41+
42+
parser = Parser()
43+
parser.feed(content)
44+
parser.close()
45+
46+
return parser.is_redirect
47+
48+
1549
def main() -> int:
1650
allowed_names = ["index.html", "404.html"]
1751
errors = list[str]()
@@ -25,6 +59,9 @@ def main() -> int:
2559
continue
2660

2761
path = cwd.joinpath(file).as_posix()
62+
if is_redirect(path):
63+
continue
64+
2865
errors.append(path)
2966

3067
if 0 < len(errors):

0 commit comments

Comments
 (0)