@charset "UTF-8";

/*!
Theme Name: Cocoon Child
Description: Cocoon専用の子テーマ
Theme URI: https://wp-cocoon.com/
Author: わいひら
Author URI: https://nelog.jp/
Template:   cocoon-master
Version:    1.1.3
*/

/************************************
** 子テーマ用のスタイルを書く
************************************/
/*必要ならばここにコードを書く*/

/************************************
** レスポンシブデザイン用のメディアクエリ
************************************/
/*1023px以下*/
@media screen and (max-width: 1023px){
  /*必要ならばここにコードを書く*/
}

/*834px以下*/
@media screen and (max-width: 834px){
  /*必要ならばここにコードを書く*/
}

/*480px以下*/
@media screen and (max-width: 480px){
  /*必要ならばここにコードを書く*/
}

/* キャプション文字拡大対応 */
.wp-caption .wp-caption-text,
figure.wp-block-image figcaption {
  font-size: 18px !important;
  line-height: 1.6;
}

/* 中央揃え：クラシックエディタ＆ブロックエディタ対応 */
figure.wp-block-image,
.wp-block-image img,
.aligncenter,
.wp-caption {
  display: block;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}
/* 本文だけ：文字サイズと行間 */
.entry-content {
  font-size: 18px;
  line-height: 1.6;
}

/* Cocoon サイドバー：カテゴリー */
.sidebar .widget_categories li a {
  line-height: 1.5;
  font-size: 16px;
  padding: 2px 0;
}

body {
    font-size: 18px !important;
    line-height: 1.6 !important;
}


// ===================================
// もおすけブログ 投稿時にスプシへ自動記入
// 対象カテゴリ：山／道具／YouTube
// ===================================
add_action('publish_post', function($post_id) {
  if (get_post_status($post_id) !== 'publish') return;
  $post = get_post($post_id);
  $cats = wp_get_post_categories($post_id, ['fields' => 'names']);

  // ★カテゴリ名 => シート名（左を実際のカテゴリ名に）
  $map = [
    '山'      => '山',
    '道具'    => '道具',
    'YouTube' => 'YouTube',
  ];
  $sheet = '';
  foreach ($cats as $c) { if (isset($map[$c])) { $sheet = $map[$c]; break; } }
  if (!$sheet) return;

  // 内部リンク抽出（最大3つ）
  preg_match_all('/<a\s[^>]*href=["\'](' . home_url() . '[^"\']*)["\']/i', $post->post_content, $m);
  $links = array_slice(array_values(array_unique($m[1])), 0, 3);

  wp_remote_post('https://script.google.com/macros/s/AKfycbxjemHYdrJMcKSZ2DdWQSHEIY1TGth8oQfGS0AV5km5Kh989tc6iCQGUcxbzFez_vxd/exec', [
    'body' => json_encode([
      'sheet' => $sheet,
      'id'    => $post_id,
      'image' => get_the_post_thumbnail_url($post_id, 'thumbnail') ?: '',
      'url'   => get_permalink($post_id),
      'title' => $post->post_title,
      'slug'  => $post->post_name,
      'links' => $links,
    ]),
    'headers' => ['Content-Type' => 'application/json'],
    'timeout' => 10,
  ]);
});