-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotfound
193 lines (135 loc) · 5.86 KB
/
notfound
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Blosxom Plugin: notfound
# Author: KITAMURA Akatsuki <[email protected]>
# Version: 2005-09-08
# Blosxom Home/Docs/Licensing: http://www.blosxom.com/
# This script is encoded in UTF-8.
package notfound;
use strict;
use CGI qw(:standard);
# --- Configurable variables -----------
# Not Found出力を避けるフレーバーの拡張子(正規表現)
# wikieditishで記事を新規追加する場合などで設定
my $flavour_re = '^wikieditish$';
# --- Plug-in package variables --------
use vars qw($url $signature);
my $stories;
# --------------------------------------
sub start {
return 0 if ($blosxom::static_or_dynamic eq 'static');
return 0 if ($flavour_re && $blosxom::flavour =~ /$flavour_re/o);
$stories = 0;
1;
}
sub filter {
return 1 unless ($blosxom::path_info);
return 1 if ($blosxom::path_info =~ m{[^/]+\.[^/]+$});
# $path_infoのディレクトリ部分に一致しないファイルを除去
my $files_ref = $_[1];
my $path_dir = "$blosxom::datadir/$blosxom::path_info";
foreach my $f (keys %$files_ref) {
$f =~ m{^$path_dir/} or delete($files_ref->{$f});
}
1;
}
sub story {
# 記事数を数える
$stories += 1;
1;
}
sub last {
# 記事があるなら何もせず復帰
$stories and return 1;
# 記事が無かったら404 Not Foundを返す
$blosxom::header->{-status} = '404 Not Found';
# テンプレート用変数の設定
$url = url(-absolute => 1, -path => 1);
$signature = server_software();
$signature =~ s{(^\w+/[\d.]+).*$}{$1};
$signature .= ' Server at ' . server_name() . ' Port ' . server_port();
# テンプレート読み込み
while (<DATA>) {
last if (/^__END__$/);
my ($flavour, $comp, $text) = split(' ', $_, 3);
$text =~ s/\\n/\n/g;
$blosxom::template{$flavour}{$comp} = $text;
}
# Not foundページのContent-Type処理
my $content_type = &$blosxom::template($blosxom::path_info, 'content_type', 'notfound');
$content_type =~ s/\n.*//s;
$blosxom::header->{-type} = $content_type;
# Not foundページの処理
my $page = &$blosxom::template($blosxom::path_info, 'page', 'notfound');
$blosxom::output = &$blosxom::interpolate($page);
1;
}
1;
__DATA__
notfound content_type text/html
notfound page <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n<html lang="en">\n<head>\n<title>404 Not Found</title>\n</head>\n<body>\n<h1>Not Found</h1>\n<p>The requested URL $notfound::url was not found on this server.</p>\n<hr>\n<address>$notfound::signature</address>\n</body>\n</html>\n
__END__
=head1 NAME
Blosxom Plug-in: notfound
=head1 SYNOPSIS
目的: 記事が無い場合にHTTPステータス "404 Not Found" を
返すためのプラグインです。
=head1 INSTALLATION
このプラグインファイルをプラグインディレクトリ($plugin_dir)に
置いて下さい。
=head1 CONFIGURATION
記事が無くても404 Not Foundを返したくない場合、
例えばwikieditishプラグインを使って新規記事を追加するような
場合には、$flavour_re にNot Foundを返さなくするフレーバーの
拡張子を、正規表現で設定して下さい。
# 拡張子 wikieditish を除外
my $flavour_re = '^wikieditish$';
# 拡張子 abc, def, ghi を除外
my $flavour_re = '^(?:abc|def|ghi)$';
content_type.notfoundテンプレートファイルで、Not Foundページの
Content-Typeを変更することができます。日本語やその他の言語の
文字コードをNot Foundページ本文に使う場合には、charsetパラメタを
適切に設定して下さい。例:
text/html; charset=shift_jis
text/html; charset=euc-jp
text/html; charset=utf-8
また、page.notfoundテンプレートファイルで、Not Foundページの本文を
変更することができます。このテンプレートでは以下の変数を使用できます。
$notfound::url は、要求されたURLです。
$notfound::signature は、サーバソフトウェア名、サーバ名、
ポート番号からなる文字列です。
=head1 VERSION
2005-09-08
=head1 VERSION HISTORY
=head2 2005-09-08
URLのカテゴリ指定で、前方部分一致するだけでも記事を表示してしまう
問題に対処しました(filterサブルーチンを追加)。
=head2 2005-04-19
http://www.akatsukinishisu.net/itazuragaki/data/blosxom/notfound/notfound-2005-04-19
Not Foundページをテンプレートファイルで変更可能にしました。
=head2 2004-11-21
http://www.akatsukinishisu.net/itazuragaki/data/blosxom/notfound/notfound-2004-11-21
=head1 AUTHOR
北村曉 (KITAMURA Akatsuki)
http://www.akatsukinishisu.net/
=head1 SEE ALSO
notfound plugin:
http://www.akatsukinishisu.net/itazuragaki/blosxom/notfound.html
Blosxom Home/Docs/Licensing: http://www.blosxom.com/
Blosxom Plugin Docs: http://www.blosxom.com/plugins/
=head1 LICENSE
This Blosxom Plug-in Copyright (c) 2004-2005, KITAMURA Akatsuki
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.