Created
October 15, 2011 00:59
-
-
Save koron/1288811 to your computer and use it in GitHub Desktop.
make vimdoc-ja using jekyll's feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
safe: false | |
auto: false | |
server: false | |
server_port: 4000 | |
base-url: http://vim-jp.org/vimdoc-ja | |
source: . | |
destination: ./_site | |
plugins: ./_plugins | |
future: true | |
lsi: false | |
pygments: false | |
markdown: rdiscount | |
permalink: date | |
maruku: | |
use_tex: false | |
use_divs: false | |
png_engine: blahtex | |
png_dir: images/latex | |
png_url: /images/latex | |
rdiscount: | |
extensions: [] | |
kramdown: | |
auto_ids: true, | |
footnote_nr: 1 | |
entity_output: as_char | |
toc_levels: 1..6 | |
use_coderay: false | |
coderay: | |
coderay_wrap: div | |
coderay_line_numbers: inline | |
coderay_line_numbers_start: 1 | |
coderay_tab_width: 4 | |
coderay_bold_every: 10 | |
coderay_css: style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>{{ page.title }}</title> | |
<meta name="Generator" content="Vim/7.3"> | |
<meta name="plugin-version" content="vim7.3_v10"> | |
<meta name="syntax" content="help"> | |
<meta name="settings" content="no_pre,use_css,expand_tabs"> | |
<link rel="stylesheet" href="style.css" type="text/css" /> | |
</head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> | |
<script src="vimdoc-ja.js" type="text/javascript"></script> | |
<body> | |
<div id="cse-search-form" style="float:right;">Loading</div> | |
<script src="//www.google.com/jsapi" type="text/javascript"></script> | |
<script type="text/javascript"> | |
google.load("search", "1", {language : "ja"}); | |
google.setOnLoadCallback(function() { | |
var customSearchControl = new google.search.CustomSearchControl("001325159752250591701:65aunpq8rlg"); | |
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); | |
var options = new google.search.DrawOptions(); | |
options.enableSearchboxOnly("http://www.google.com/cse?cx=001325159752250591701:65aunpq8rlg"); | |
customSearchControl.draw("cse-search-form", options); | |
}, true); | |
</script> | |
<link rel="stylesheet" href="//www.google.com/cse/style/look/default.css" type="text/css" /> | |
{{ content }} | |
<hr> | |
<a href="#top">top</a> - <a href="index.html">main help file</a><br> | |
<div style="text-align:right;"> | |
Translated by <a href="https://github.com/vim-jp/vimdoc-ja">vimdoc-ja プロジェクト</a><br /> | |
<a href="https://github.com/vim-jp/vimdoc-ja/zipball/master">ヘルプ一式ダウンロード</a><br /> | |
間違いを見つけたら<a href="http://groups.google.com/group/vimdoc-ja">メーリングリスト</a>か<a href="https://github.com/vim-jp/vimdoc-ja/issues">issueトラッカー</a>でお知らせください。<br /> | |
<a href="https://github.com/vim-jp/vimdoc-ja/wiki/HowToContribute">参加者募集中。</a><br /> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use utf8; | |
use strict; | |
use warnings; | |
use IO::File; | |
use File::Next; | |
&conver_all_html('.'); | |
# | |
# Convert all HTML to use Jekyll layout in current dir (not recursively). | |
# | |
sub conver_all_html { | |
my ($dir) = @_; | |
my $files = File::Next::files({ file_filter => sub { | |
$_ =~ m/\.html$/ and $File::Next::dir eq $dir | |
} }, $dir); | |
while (my $file = $files->()) { | |
&convert_to_jekyll($file); | |
} | |
} | |
# | |
# Convert one HTML to use Jekyll layout. | |
# | |
# 1. check converted or not. | |
# 2. store all lines to output in @out. | |
# 3. override source file with contents of @out. | |
# | |
sub convert_to_jekyll { | |
my ($filename) = @_; | |
my $in = IO::File->new($filename, 'r') or die $!; | |
$in->binmode; | |
# Check converted already. | |
my $first_line = $in->getline; | |
if ($first_line =~ m/^---/) { | |
return; | |
} | |
my @out; | |
my $title = '(WARNING: NO TITLE)'; | |
# Skip header. | |
while (my $line = $in->getline) { | |
if ($line =~ m!<link rel="stylesheet" href="//www\.google\.com/cse/style/look/default\.css" type="text/css" />!) { | |
last; | |
} elsif ($line =~ m/<title>([^<]*)<\/title>/) { | |
$title = $1; | |
} | |
} | |
# Compose new YAML header. | |
push @out, "---\n"; | |
push @out, "layout: vimdoc\n"; | |
push @out, sprintf("title: '%s'\n", $title); | |
push @out, "---\n"; | |
# Reserve to output body. | |
my $hr_count = 0; | |
while (my $line = $in->getline) { | |
# FIXME: Finish condition is too heuristic. | |
if ($line =~ m/^<hr>/) { | |
if (++$hr_count >= 2) { | |
last; | |
} | |
} | |
push @out, $line; | |
} | |
# Skip remained footer. | |
$in->close; | |
# Output new file. | |
my $out = IO::File->new($filename, 'w') or die $!; | |
$out->binmode; | |
print $out @out; | |
$out->close; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment