Skip to content

Commit

Permalink
slot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
naga3 committed May 22, 2017
1 parent be28b56 commit d62a995
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# ssj
超簡易静的サイトジェネレーター

// 超簡易静的サイトジェネレーター
// index.htmlの<!-- {***} --><!-- /{***} -->で囲まれた部分を
// 他のHTMLにコピーする。
// ***に入る文字列は header, sidebar, footer のいずれか。
33 changes: 33 additions & 0 deletions company.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- {header} -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>タイトル</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
<h1><!-- {s1} -->トップページ<!-- /{s1} --></h1>
<a href="./">トップページ</a>
<a href="company.html">会社概要</a>
<a href="contact.html">お問い合わせ</a>
</header>
<!-- /{header} -->
<div id="container">
<!-- {sidebar} -->
<aside>
サイドバー
</aside>
<!-- /{sidebar} -->
<article>
会社概要
</article>
</div>
<!-- {footer} -->
<footer>
<!-- {s2} -->フッタ<!-- /{s2} -->
</footer>
</body>
</html>
<!-- /{footer} -->
33 changes: 33 additions & 0 deletions contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- {header} -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>タイトル</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
<h1><!-- {s1} -->トップページ<!-- /{s1} --></h1>
<a href="./">トップページ</a>
<a href="company.html">会社概要</a>
<a href="contact.html">お問い合わせ</a>
</header>
<!-- /{header} -->
<div id="container">
<!-- {sidebar} -->
<aside>
サイドバー
</aside>
<!-- /{sidebar} -->
<article>
お問い合わせ
</article>
</div>
<!-- {footer} -->
<footer>
<!-- {s2} -->フッタ<!-- /{s2} -->
</footer>
</body>
</html>
<!-- /{footer} -->
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- {header} -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>タイトル</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
<h1><!-- {s1} -->トップページ<!-- /{s1} --></h1>
<a href="./">トップページ</a>
<a href="company.html">会社概要</a>
<a href="contact.html">お問い合わせ</a>
</header>
<!-- /{header} -->
<div id="container">
<!-- {sidebar} -->
<aside>
サイドバー
</aside>
<!-- /{sidebar} -->
<article>
トップページ
</article>
</div>
<!-- {footer} -->
<footer>
<!-- {s2} -->フッタ<!-- /{s2} -->
</footer>
</body>
</html>
<!-- /{footer} -->
17 changes: 17 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
header, footer {
background: #ffc;
text-align: center;
padding: 20px 0;
}
#container {
display: flex;
height: 300px;
}
aside {
flex: 1;
background: #fcc;
}
article {
flex: 2;
background: #cff;
}
29 changes: 29 additions & 0 deletions ssj.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
// Seiteki Saito Jenereetaa

// 反映元
$src = 'index.html';

// 反映先
$dists = ['company.html', 'contact.html'];

// セクション
$sections = ['header', 'sidebar', 'footer'];

$parts = [];
$html = file_get_contents($src);
foreach ($sections as $section) {
preg_match('|<!-- {' . $section . '} -->(.*?)<!-- /{' . $section . '} -->|s', $html, $ms);
$parts[$section] = $ms[1];
}
preg_match_all('|<!-- {s(\d+?)} -->(.*?)<!-- /{s\d+?} -->|s', $html, $mss, PREG_SET_ORDER);
$slots = [];
foreach ($mss as $ms) $slots[$ms[1]] = $ms[2];
foreach ($dists as $dist) {
$html = file_get_contents($dist);
foreach ($parts as $section => $part) {
$html = preg_replace('|(<!-- {' . $section . '} -->)(.*?)(<!-- /{' . $section . '} -->)|s', "$1$part$3", $html);
}
file_put_contents($dist, $html);
echo "$dist OK<br>";
}

0 comments on commit d62a995

Please sign in to comment.