-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile.php
executable file
·120 lines (113 loc) · 3.81 KB
/
compile.php
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
#!/usr/bin/env php
<?php
if ( isset( $argv[ 1 ] ) ) {
die( 'タイトルは決定済みです。' );
}
$title = 'オートマティック クリミナル';
$path = __DIR__ . '/manuscript.txt';
$title = htmlspecialchars( $title );
$content = file_get_contents( $path );
// ルビを変換
$content = preg_replace( '/\|([^<]+)<(.*?)>/u', '<ruby>$1<rt>$2</rt></ruby>', $content );
// 強調を変換
$content = preg_replace_callback( '/\[(.*?)\]/u', function ( $match ) {
$letters = $match[ 1 ];
$emphasized = '';
for ( $i = 0, $l = mb_strlen( $letters, 'utf-8' ); $i < $l; $i ++ ) {
$letter = mb_substr( $letters, $i, 1, 'utf-8' );
$emphasized .= sprintf( '<ruby>%s<rt>・</rt></ruby>', $letter );
}
return $emphasized;
}, $content );
// 改行の中身を全部タグに変換
$content = implode( "\n", array_map( function ( $line ) {
$first_letter = mb_substr( $line, 0, 1, 'utf-8' );
$second_letters = function ( $line ) {
return mb_substr( $line, 1, mb_strlen( $line ) - 1 );
};
switch ( $first_letter ) {
case '>':
return sprintf( '<blockquote>%s</blockquote>', $second_letters( $line ) );
case '<':
return sprintf( '<p class="right">%s</p>', $second_letters( $line ) );
case '~':
return sprintf( '<p class="center">%s</p>', $second_letters( $line ) );
case '':
return '<p> </p>';
default:
return sprintf( '<p>%s</p>', $line );
}
}, explode( "\n", $content ) ) );
ob_start();
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title><?= $title ?></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
media="screen"/>
<link rel="stylesheet" href="./style.css" media="screen"/>
<link rel="stylesheet" href="./print.css" media="print"/>
<meta property="og:url" content="http://github.takahashifumiki.com/noveljam2018/">
<meta property="og:type" content="article">
<meta property="og:title" content="<?= $title ?>">
<meta property="og:image" content="http://github.takahashifumiki.com/noveljam2018/cover.jpg">
<meta property="og:description" content="NovalJam 2018に著者として参加する高橋文樹のリポジトリです。">
<meta property="fb:app_id" content="264573556888294">
</head>
<body>
<header>
<h1><?= $title ?></h1>
</header>
<div class="main">
<h1 class="print-title">
<?= $title ?>
<small>高橋文樹</small>
</h1>
<?= $content ?>
</div>
<footer>
<a href="https://github.com/fumikito/noveljam2018"><i class="fa fa-github"></i></a>
<p>
© 2018 <a href="https://takahashifumiki.com">Takahashi Fumiki</a>
</p>
</footer>
</body>
<div class="backdrop">
<div class="question">
<p>
最後までお読みいただき、ありがとうございます!
アンケートにお答えください。
</p>
<div>
<?php foreach (
[
'面白かったので買う' => 200,
'面白かったが買わない' => 0,
'つまらないので買わない' => 0,
'つまらないが買う' => 200,
] as $label => $value
) : ?>
<div class="button" role="button" data-action="<?= $label ?>" data-value="<?= $value ?>">
<i class="fa fa-circle-o off"></i>
<i class="fa fa-dot-circle-o on"></i>
<?= $label ?>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-5329295-4"></script>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="./script.js"></script>
</html>
<?php
$html = ob_get_contents();
ob_end_clean();
$target = __DIR__ . '/docs/index.html';
if ( ! is_dir( dirname( $target ) ) ) {
mkdir( dirname( $target ) );
}
file_put_contents( $target, $html );