Skip to content

Commit 2d80f5b

Browse files
committed
1.0.7
1 parent c188209 commit 2d80f5b

13 files changed

+339
-62
lines changed

css/prism.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

footer.php

+42-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,46 @@
11
<footer class="footer">
22
<script src="<?php echo get_template_directory_uri(); ?>/js/control.js"></script>
3+
<script src="<?php echo get_template_directory_uri(); ?>/js/clipboard.min.js"></script>
34
<script src="<?php echo get_template_directory_uri(); ?>/js/sweetalert2.min.js"></script>
45
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/sweetalert2.min.css">
56
<script>
7+
<?php if (get_theme_mod("or_ads_id")): ?>
8+
(function(window, document) {
9+
function main() {
10+
var ad = document.createElement('script');
11+
ad.async = true;
12+
ad.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=<?php echo get_theme_mod(
13+
"or_ads_id"
14+
); ?>';
15+
ad.crossOrigin = "anonymous"
16+
var sc = document.getElementsByTagName('script')[0];
17+
sc.parentNode.insertBefore(ad, sc);
18+
}
19+
20+
var lazyLoad = false;
21+
function onLazyLoad() {
22+
if (lazyLoad === false) {
23+
lazyLoad = true;
24+
window.removeEventListener('scroll', onLazyLoad);
25+
window.removeEventListener('mousemove', onLazyLoad);
26+
window.removeEventListener('mousedown', onLazyLoad);
27+
window.removeEventListener('touchstart', onLazyLoad);
28+
window.removeEventListener('keydown', onLazyLoad);
29+
main();
30+
}
31+
}
32+
window.addEventListener('scroll', onLazyLoad);
33+
window.addEventListener('mousemove', onLazyLoad);
34+
window.addEventListener('mousedown', onLazyLoad);
35+
window.addEventListener('touchstart', onLazyLoad);
36+
window.addEventListener('keydown', onLazyLoad);
37+
window.addEventListener('load', function() {
38+
if (window.pageYOffset) {
39+
onLazyLoad();
40+
window.setTimeout(onLazyLoad,3000)
41+
}
42+
});
43+
})(window, document);
644
function toggleNav() {
745
var a = document.getElementById('hamburgerbtn'),
846
b = document.getElementById('overlay'),
@@ -13,9 +51,8 @@ function toggleNav() {
1351
c.classList.toggle('scroll-lock');
1452
});
1553
}
54+
<?php endif; ?>
1655
toggleNav();
17-
hljs.initHighlightingOnLoad();
18-
hljs.initLineNumbersOnLoad();
1956
new ClipboardJS('.url');
2057
function OnClickURL() {
2158
Swal.fire({
@@ -27,9 +64,9 @@ function OnClickURL() {
2764
}
2865
</script>
2966
<div>
30-
<p>CopyRight &copy; <?php echo date('Y'); ?> <a href="<?php bloginfo(
31-
'url'
32-
); ?>"><?php bloginfo('name'); ?></a>.</p>
67+
<p>CopyRight &copy; <?php echo date("Y"); ?> <a href="<?php bloginfo(
68+
"url"
69+
); ?>"><?php bloginfo("name"); ?></a>.</p>
3370
</div>
3471
</footer>
3572
</body>

functions.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function or_setup()
1111
add_action("after_setup_theme", "or_setup");
1212

1313
include "inc/customizer.php";
14+
include "inc/toc.php";
1415

1516
// SVG対応
1617
function custom_mime_types($mimes)

header.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@
99
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" />
1010
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/icon.css" />
1111
<?php if (is_front_page() || is_home()): ?>
12-
<title><?php bloginfo('name'); ?></title>
12+
<title><?php bloginfo("name"); ?></title>
1313
<?php elseif (is_singular()): ?>
14-
<title><?php the_title(); ?> | <?php bloginfo('name'); ?></title>
14+
<title><?php the_title(); ?> | <?php bloginfo("name"); ?></title>
1515
<?php elseif (is_category() || is_tag()): ?>
16-
<title><?php single_cat_title(); ?> | <?php bloginfo('name'); ?></title>
16+
<title><?php single_cat_title(); ?> | <?php bloginfo("name"); ?></title>
1717
<?php else: ?>
18-
<title><?php the_title(); ?> | <?php bloginfo('name'); ?></title>
18+
<title><?php the_title(); ?> | <?php bloginfo("name"); ?></title>
1919
<?php endif; ?>
20-
<?php if (get_theme_mod('or_main_design_googlefonts')): ?>
20+
<?php
21+
if (get_theme_mod("or_main_design_googlefonts")): ?>
2122
<link rel="preconnect" href="https://fonts.googleapis.com" />
2223
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
2324
<link href="https://fonts.googleapis.com/css2?family=<?php
24-
$values = get_theme_mod('or_main_design_googlefonts');
25-
echo str_replace(',', ':wght@400;700&', $values . ',');
25+
$values = get_theme_mod("or_main_design_googlefonts");
26+
echo str_replace(",", ":wght@400;700&", $values . ",");
2627
?>display=swap" rel="stylesheet">
27-
<?php endif; ?>
28-
<?php wp_head(); ?>
28+
<?php endif;
29+
wp_head();
30+
?>
2931
</head>
3032

3133
<body>
@@ -38,14 +40,14 @@
3840
echo '<a href="' .
3941
home_url() .
4042
'" rel="home">' .
41-
get_bloginfo('name') .
42-
'</a>';
43+
get_bloginfo("name") .
44+
"</a>";
4345
}
4446
?>
4547
</h2>
4648
<?php
4749
$args = [
48-
'container' => false,
50+
"container" => false,
4951
];
5052
wp_nav_menu($args);
5153
?>

inc/customizer.php

+50-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function or_customize($wp_customize)
44
include "control.php";
55
$wp_customize->add_panel("or_design", [
66
"title" => "デザイン",
7-
"priority" => 300,
7+
"priority" => 700,
88
]);
99

1010
// 全体
@@ -195,6 +195,15 @@ function or_customize($wp_customize)
195195
])
196196
);
197197

198+
$wp_customize->add_setting("or_single_design_toc");
199+
$wp_customize->add_control(
200+
new WP_Customize_Control($wp_customize, "or_single_design_toc", [
201+
"label" => "目次を表示しない",
202+
"section" => "or_single_design",
203+
"type" => "checkbox",
204+
])
205+
);
206+
198207
$wp_customize->add_section("or_mobile_design", [
199208
"title" => "モバイル",
200209
"panel" => "or_design",
@@ -280,7 +289,7 @@ function or_customize($wp_customize)
280289
// SNS
281290
$wp_customize->add_section("or_sns", [
282291
"title" => "SNS",
283-
"priority" => 400,
292+
"priority" => 750,
284293
]);
285294

286295
$wp_customize->add_setting("or_sns_services");
@@ -324,14 +333,23 @@ function or_customize($wp_customize)
324333
// 広告
325334
$wp_customize->add_section("or_ads", [
326335
"title" => "広告",
327-
"priority" => 500,
336+
"priority" => 800,
328337
]);
329338

339+
$wp_customize->add_setting("or_ads_id");
340+
$wp_customize->add_control(
341+
new WP_Customize_Control($wp_customize, "or_ads_id", [
342+
"label" => "サイト運営者ID",
343+
"description" => "例:ca-pub-0000000000000000",
344+
"section" => "or_ads",
345+
])
346+
);
347+
330348
$wp_customize->add_setting("or_ads_display");
331349
$wp_customize->add_control(
332350
new WP_Customize_Control($wp_customize, "or_ads_display", [
333351
"label" => "ディスプレイ広告",
334-
"description" => "実装予定",
352+
"description" => "例:&lt;ins&gt;...&lt;/ins&gt;",
335353
"section" => "or_ads",
336354
"type" => "textarea",
337355
])
@@ -345,10 +363,12 @@ function or_customize($wp_customize)
345363
[
346364
"section" => "or_ads",
347365
"label" => "配置箇所",
348-
"description" => "広告の配置場所を選択(実装予定)",
366+
"description" => "ディスプレイ広告の配置場所を選択",
349367
"choices" => [
350-
"article_top" => "記事本文上",
351-
"article_bottom" => "記事本文下",
368+
"single_top" => "記事本文上",
369+
"single_bottom" => "記事本文下",
370+
"page_top" => "固定ページ本文上",
371+
"page_bottom" => "固定ページ本文下",
352372
],
353373
]
354374
)
@@ -358,17 +378,29 @@ function or_customize($wp_customize)
358378
$wp_customize->add_control(
359379
new WP_Customize_Control($wp_customize, "or_ads_infeed", [
360380
"label" => "インフィード広告",
361-
"description" => "実装予定",
381+
"description" => "例:&lt;ins&gt;...&lt;/ins&gt;",
362382
"section" => "or_ads",
363383
"type" => "textarea",
364384
])
365385
);
366386

367-
$wp_customize->add_setting("or_ads_infeed_counts");
387+
$wp_customize->add_setting("or_ads_infeed_counts", [
388+
"default" => 3,
389+
]);
368390
$wp_customize->add_control(
369391
new WP_Customize_Control($wp_customize, "or_ads_infeed_counts", [
370392
"label" => "表示間隔",
371-
"description" => "実装予定",
393+
"section" => "or_ads",
394+
"type" => "number",
395+
])
396+
);
397+
$wp_customize->add_setting("or_ads_infeed_max", [
398+
"default" => 3,
399+
]);
400+
$wp_customize->add_control(
401+
new WP_Customize_Control($wp_customize, "or_ads_infeed_max", [
402+
"label" => "最大表示数",
403+
"description" => "1ページの最大表示数",
372404
"section" => "or_ads",
373405
"type" => "number",
374406
])
@@ -401,6 +433,9 @@ function theme_customize_css()
401433
color: <?php echo get_theme_mod("or_header_design_color"); ?>;
402434
<?php endif; ?>
403435
}
436+
header nav .mobile span {
437+
background: <?php echo get_theme_mod("or_header_design_bgcolor"); ?>;
438+
}
404439
footer.footer {
405440
<?php if (get_theme_mod("or_footer_design_bgcolor")): ?>
406441
background-color: <?php echo get_theme_mod("or_footer_design_bgcolor"); ?>;
@@ -433,6 +468,11 @@ function theme_customize_css()
433468
grid-template-columns: repeat(3, minmax(0, 1fr));
434469
}
435470
<?php endif; ?>
471+
<?php if (get_theme_mod("or_single_design_toc")): ?>
472+
.content.article .toc {
473+
display: none;
474+
}
475+
<?php endif; ?>
436476
<?php if (get_theme_mod("or_mobile_design_sidebar")): ?>
437477
.sidebar {
438478
display: none;

inc/toc.php

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
function add_index($content)
3+
{
4+
if (is_single()) {
5+
$pattern = "/<h[1-6].*?>(.+?)<\/h[1-6]>/s";
6+
preg_match_all($pattern, $content, $elements, PREG_SET_ORDER);
7+
8+
if (count($elements) >= 1) {
9+
$toc = "";
10+
$currentlevel = 0;
11+
$i = 1;
12+
13+
foreach ($elements as $element) {
14+
$regex = "/" . preg_quote($element[0], "/") . "/su";
15+
preg_match(
16+
'/<(h[1-6] id="(.*)?")>(.+)?<\/(h[1-6])>/s',
17+
$element[0],
18+
$id
19+
);
20+
21+
$id[2] = empty($id[2]) ? "chapter-" . $i : $id;
22+
23+
if (strpos($element[0], "<h2") !== false) {
24+
$level = 1;
25+
} elseif (strpos($element[0], "<h3") !== false) {
26+
$level = 2;
27+
} elseif (strpos($element[0], "<h4") !== false) {
28+
$level = 3;
29+
} elseif (strpos($element[0], "<h5") !== false) {
30+
$level = 4;
31+
} elseif (strpos($element[0], "<h6") !== false) {
32+
$level = 5;
33+
}
34+
35+
while ($currentlevel < $level) {
36+
if (0 === $currentlevel) {
37+
$toc .= '<ol class="toc__list">';
38+
} else {
39+
$toc .= '<ol class="toc__list_child">';
40+
}
41+
$currentlevel++;
42+
}
43+
44+
while ($currentlevel > $level) {
45+
$toc .= "</li></ol>";
46+
$currentlevel--;
47+
}
48+
49+
$toc .=
50+
'<li class="toc__item"><a href="#' .
51+
$id[2] .
52+
'" class="toc__link">' .
53+
$element[1] .
54+
"</a>";
55+
$i++;
56+
}
57+
58+
while ($currentlevel > 0) {
59+
$toc .= "</li></ol>";
60+
$currentlevel--;
61+
}
62+
63+
$index =
64+
'<details class="toc" open><summary class="toc__title">目次</summary>' .
65+
$toc .
66+
"</details>";
67+
$h2 = "/<h2.*?>/i";
68+
69+
if (preg_match($h2, $content, $h2s)) {
70+
$content = preg_replace($h2, $index . $h2s[0], $content, 1);
71+
}
72+
}
73+
}
74+
return $content;
75+
}
76+
if (!get_theme_mod("or_single_design_toc")):
77+
add_filter("the_content", "add_index");
78+
endif;

0 commit comments

Comments
 (0)