Plugin Directory

Changeset 3690707


Ignore:
Timestamp:
09/11/2026 03:35:02 AM (2 months ago)
Author:
youheiokubo
Message:

1.8.0: Markdown export scoping (post type / publish date / individual pages) and optional HTML comment stripping

Location:
distan/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • distan/trunk/ai-reference.md

    r3687297 r3690707  
    2929- **検索エンジンの扱い** — noindex を除去(本番納品・既定)か、残す(テスト環境での確認用)。
    3030- **WordPress の痕跡を除く** — generator / RSD / oEmbed / 絵文字 / ショートリンク等のメタ情報を除去(既定オン)。※ ブロック用 CSS やプラグイン JS は対象外。特定ページから外すのはテンプレート書き出しのマーカー。
     31- **HTMLコメントを削除**(`strip_comments`・既定オフ)— 納品 HTML からプレーンな HTML コメント(`<!-- ... -->`)を除去。`Distan_Cleaner::strip_comments()` を **`apply_page_markers` の後・書き出し直前**(generator 312→314 の間)で適用するため、`distan:` マーカーは既に消費・除去済みで競合しない。`<script>`/`<style>`/`<textarea>`/`<pre>` の中身は退避して保護、IE 条件付きコメント(`<!--[if ...]>`)は実マークアップを囲みうるため残す。PCRE 失敗時は入力をそのまま返す(空白ページ化を防ぐフェイルセーフ)。clean_html とは独立。
    3132- **Markdown を書き出す** — 全ページ本文を 1 ファイル `content.md` に(AI ツール向け)。既定オフ。
    3233  - Markdown 書き出しの変換(html_to_markdown): 見出し/リンク/箇条書きに加え、表→パイプ表、`<pre>`→フェンス・`<code>`→バッククォート、`<img>`→`![alt](src)`、blockquote→`>`、strong/em→`**`/`*`、`<ol>`→番号付き、`<hr>`→`---`。パス順は「コード保護→表→見出し→引用→画像→リンク→強調→リスト→hr/p/br→strip」。表セルはリンクのラベルのみ残し装飾は素テキスト。各セクションに title/元URL/description(metaから)を付与。title は <title>→本文の最初の h1→URL の順でフォールバック(title-tag 非対応テーマ対策)、本文先頭がそのタイトル見出しと重複する場合は本文側を除去
     34  - Markdown の絞り込み(`Distan_Markdown::wants`): **何も指定しなければ全ページ**(投稿・CPT・固定ページ・トップ・アーカイブ)が対象=1.7 以前と同じ full export。絞り込みは任意で、投稿タイプ・公開日・個別ページを設定したときだけ効く。静的サイト(dist/)の生成内容には影響しない content.md 側だけのゲートで、判定は generator の書き出し直前 `is_enabled() && wants($item)`。フィルタ設定時の挙動——(1) **投稿タイプ+公開日**: `md_post_types`(チェックしたタイプだけ/空なら投稿タイプでは絞らない)と `md_date_from`/`md_date_to`(YYYY-MM-DD、両端含む・片側省略可、サイトTZの暦日比較)。**絞り込みが有効なときは**投稿タイプを持たないアイテム(トップ・タームアーカイブ・404)と固定ページが外れる(固定ページは下の個別指定で戻す)。(2) **個別の固定ページ**: `md_pages`(ページ ID)。UI はテンプレート書き出しと同じ検索+セレクト+「追加」でチップ選択(`x-model` なしで候補が絞られ該当を自動選択、送信値は `picks` から hidden 出力)。投稿タイプ・公開日の絞り込みに関係なく常に採用(=人の明示宣言)
    3335- **サイトマップを書き出す** — `sitemap.xml`。除外パターンを指定できる。既定オフ。
    3436- **robots.txt を書き出す** — 最小構成(`Allow: /`)。既定オフ。
    … …  
    6567- **列挙の由来(provenance)** — 生成した各ページに由来(投稿とその ID/タクソノミー・ターム/アーカイブのページ番号など)を記録。差分レポートはファイルパスだけでなく「投稿タイトル [投稿 #123]」の形で変更を名指す。増分スキップはしない(毎回すべて再生成する)
    6668- **大きいファイルの検出と警告** — 画像・PDF・フォント・動画などバイナリはストリームコピー(メモリに全体を載せない)。一定サイズ超(既定 10MB、`distan_large_file_threshold` フィルタ)はレポートに一覧表示。コピーはするので手作業は不要(納品サイズや CDN 検討の目安)。CSS だけは url() 書き換えのためメモリに読む
    67 - **Markdown 書き出し(選択制)** — 全ページ本文を 1 ファイル `content.md` にまとめる。Gemini Notebook(旧NotebookLM)等の AI ツール向け。ページネーションは除外。URL は公開 URL に置換(開発用に `content.local.md` も選択可)
     69- **Markdown 書き出し(選択制)** — 全ページ本文を 1 ファイル `content.md` にまとめる。Gemini Notebook(旧NotebookLM)等の AI ツール向け。ページネーションは除外。URL は公開 URL に置換(開発用に `content.local.md` も選択可)。投稿タイプ・公開日(min〜max)で対象を絞り込め、固定ページはタイトル検索で個別に含められる(記事だけを AI に読ませる等)。絞り込みは content.md 側だけに効き、静的サイトの生成内容は変えない
    6870- **サイトマップ書き出し(選択制)** — 生成したページから `sitemap.xml` を作る(Google Search Console 対応の標準形式)。URL は公開 URL。著者・日付アーカイブは収集対象外なので `?author=1` 等の ID は載らない。`/private/`(スラッグ以下)や `draft`(語を含む)で除外指定できる(設定 または `distan_sitemap_exclude` フィルタ)
    6971- **robots.txt 書き出し(選択制)** — 最小構成(`Allow: /`)。サイトマップが有効なときは `Sitemap:` 行も記載。既にサーバーに robots.txt がある場合はオフにする
  • distan/trunk/assets/css/distan-admin.css

    r3682850 r3690707  
    11271127        margin: var(--sp-xs) 0 0;
    11281128}
     1129
     1130/* Markdown filter (content.md scope): post types, publish-date range and
     1131   hand-picked pages. Sits under the "write Markdown" toggle and follows the
     1132   same slip aesthetic — hairline groups doing the structural work, 2px
     1133   radius, tokens throughout, accent used sparingly. */
     1134.hgp-md-filter {
     1135        margin-top: var(--sp-md);
     1136        padding-top: var(--sp-md);
     1137        border-top: 1px solid var(--dsp-line);
     1138}
     1139
     1140.hgp-md-filter .hgp-md-filter__intro {
     1141        margin: 0 0 var(--sp-md);
     1142        font-size: var(--fs-body);
     1143        color: var(--dsp-slate);
     1144}
     1145
     1146.hgp-md-filter__group {
     1147        margin: 0;
     1148}
     1149
     1150.hgp-md-filter__group + .hgp-md-filter__group {
     1151        margin-top: var(--sp-md);
     1152        padding-top: var(--sp-md);
     1153        border-top: 1px solid var(--dsp-line);
     1154}
     1155
     1156.hgp-md-filter__legend {
     1157        margin: 0 0 var(--sp-sm);
     1158        font-size: var(--fs-body);
     1159        font-weight: 700;
     1160        color: var(--dsp-ink);
     1161}
     1162
     1163.hgp-md-filter__head {
     1164        display: flex;
     1165        align-items: baseline;
     1166        justify-content: space-between;
     1167        gap: var(--sp-md);
     1168        margin: 0 0 var(--sp-sm);
     1169}
     1170
     1171.hgp-md-filter__head .hgp-md-filter__legend {
     1172        margin: 0;
     1173}
     1174
     1175.hgp-md-filter__reset {
     1176        flex: none;
     1177        padding: 0;
     1178        border: 0;
     1179        background: transparent;
     1180        color: var(--dsp-slate);
     1181        font-size: var(--fs-meta);
     1182        text-decoration: underline;
     1183        cursor: pointer;
     1184}
     1185
     1186.hgp-md-filter__reset:hover,
     1187.hgp-md-filter__reset:focus {
     1188        color: var(--dsp-stamp);
     1189}
     1190
     1191.hgp-md-filter .description {
     1192        margin: var(--sp-sm) 0 0;
     1193}
     1194
     1195/* Post types — labels wrap inline as a row of chips. */
     1196.hgp-md-filter__types {
     1197        display: flex;
     1198        flex-wrap: wrap;
     1199        gap: var(--sp-xs) var(--sp-md);
     1200}
     1201
     1202.hgp-md-filter__type {
     1203        display: inline-flex;
     1204        align-items: center;
     1205        gap: 6px;
     1206        margin: 0;
     1207        font-size: var(--fs-body);
     1208}
     1209
     1210.hgp-md-filter__slug {
     1211        padding: 1px 6px;
     1212        background: var(--dsp-ground);
     1213        border: 1px solid var(--dsp-line);
     1214        border-radius: 2px;
     1215        font-family: var(--dsp-mono);
     1216        font-size: 11px;
     1217        color: var(--dsp-slate);
     1218}
     1219
     1220/* Publish-date range. */
     1221.hgp-md-filter__dates {
     1222        display: flex;
     1223        align-items: center;
     1224        flex-wrap: wrap;
     1225        gap: var(--sp-xs) var(--sp-sm);
     1226}
     1227
     1228.hgp-md-filter__date {
     1229        display: inline-flex;
     1230        align-items: center;
     1231        gap: 6px;
     1232        margin: 0;
     1233        font-size: var(--fs-body);
     1234}
     1235
     1236.hgp-md-filter__date input[type="date"] {
     1237        padding: 3px 8px;
     1238        border: 1px solid var(--dsp-line);
     1239        border-radius: 2px;
     1240}
     1241
     1242.hgp-md-filter__dash {
     1243        color: var(--dsp-slate);
     1244}
     1245
     1246.hgp-md-filter__warn {
     1247        color: var(--dsp-danger);
     1248}
     1249
     1250/* Hand-picked pages — search + add-dropdown row (reuses .hgp-template__row),
     1251   selected pages shown as removable chips. */
     1252.hgp-md-filter__count {
     1253        margin: var(--sp-xs) 0 0;
     1254        font-size: var(--fs-meta);
     1255        color: var(--dsp-slate);
     1256}
     1257
     1258.hgp-md-filter__chips {
     1259        display: flex;
     1260        flex-wrap: wrap;
     1261        gap: var(--sp-xs);
     1262        margin-top: var(--sp-sm);
     1263}
     1264
     1265.hgp-md-filter__chip {
     1266        display: inline-flex;
     1267        align-items: center;
     1268        gap: 6px;
     1269        padding: 2px 4px 2px 10px;
     1270        background: var(--dsp-ground);
     1271        border: 1px solid var(--dsp-line);
     1272        border-radius: 2px;
     1273        font-size: var(--fs-meta);
     1274        color: var(--dsp-ink);
     1275}
     1276
     1277.hgp-md-filter__chip-x {
     1278        display: inline-flex;
     1279        align-items: center;
     1280        justify-content: center;
     1281        width: 18px;
     1282        height: 18px;
     1283        padding: 0;
     1284        border: 0;
     1285        border-radius: 2px;
     1286        background: transparent;
     1287        color: var(--dsp-slate);
     1288        font-size: 15px;
     1289        line-height: 1;
     1290        cursor: pointer;
     1291}
     1292
     1293.hgp-md-filter__chip-x:hover,
     1294.hgp-md-filter__chip-x:focus {
     1295        background: var(--dsp-danger-tint);
     1296        color: var(--dsp-danger);
     1297}
     1298
     1299/* Match the template-export row proportions: keep the add-dropdown a
     1300   sensible width instead of shrinking to the placeholder. Scoped to the
     1301   Markdown picker so the template-export select is untouched. */
     1302.hgp-md-filter .hgp-template__row select {
     1303        min-width: 240px;
     1304        max-width: 100%;
     1305}
  • distan/trunk/distan.php

    r3687297 r3690707  
    44 * Plugin URI:  https://github.com/okuboyouhei/distan
    55 * Description: dist で開発する、WordPress静的サイトジェネレーター。HTML納品案件のために、WordPressを制作環境として使い、余計なものを含まない静的HTMLを書き出します。
    6  * Version:     1.7.0
     6 * Version:     1.8.0
    77 * Author:      Youhei Okubo
    88 * License:     GPL-2.0-or-later
    … …  
    1717defined( 'ABSPATH' ) || exit;
    1818
    19 define( 'DISTAN_VERSION', '1.7.0' );
     19define( 'DISTAN_VERSION', '1.8.0' );
    2020define( 'DISTAN_FILE', __FILE__ );
    2121define( 'DISTAN_DIR', plugin_dir_path( __FILE__ ) );
    … …  
    115115                        'strip_noindex' => true,   // false keeps robots noindex (staging preview).
    116116                        'keep_indent'   => true,
     117                        'strip_comments' => false, // Remove plain HTML comments from the delivered pages (opt-in).
    117118                        'export_markdown' => false, // Write a combined content.md for AI tools (Gemini Notebook, formerly NotebookLM).
    118119                        'export_markdown_local' => false, // Also write content.local.md keeping development URLs.
     120                        'md_post_types'   => array(), // Markdown: limit content.md to these post types. Empty = every type except 'page'.
     121                        'md_date_from'    => '',    // Markdown: only posts published on/after this date (YYYY-MM-DD). Empty = no lower bound.
     122                        'md_date_to'      => '',    // Markdown: only posts published on/before this date (YYYY-MM-DD). Empty = no upper bound.
     123                        'md_pages'        => array(), // Markdown: page IDs hand-picked to always include, ignoring the date filter.
    119124                        'sitemap'         => false, // Write a standards-compliant sitemap.xml from the generated pages.
    120125                        'sitemap_exclude' => '',    // Newline-separated slug prefixes (/private/) or substrings (draft) to exclude.
  • distan/trunk/includes/class-distan-admin.php

    r3682850 r3690707  
    318318                $out['strip_noindex'] = ! empty( $input['strip_noindex'] );
    319319                $out['keep_indent'] = isset( $input['keep_indent'] ) ? ! empty( $input['keep_indent'] ) : true;
     320                $out['strip_comments'] = ! empty( $input['strip_comments'] );
    320321                $out['export_markdown'] = ! empty( $input['export_markdown'] );
    321322                $out['export_markdown_local'] = ! empty( $input['export_markdown_local'] );
     323
     324                // Markdown filter: post types (never 'page'; that has its own track).
     325                $md_types_in  = isset( $input['md_post_types'] ) ? (array) $input['md_post_types'] : array();
     326                $md_types_ok  = array_values( array_filter( Distan_Collector::post_types(), static function ( $t ) {
     327                        return 'page' !== $t;
     328                } ) );
     329                $out['md_post_types'] = array_values( array_intersect(
     330                        array_map( 'sanitize_key', array_map( 'strval', $md_types_in ) ),
     331                        $md_types_ok
     332                ) );
     333
     334                // Markdown filter: publish-date range (YYYY-MM-DD, or empty).
     335                $out['md_date_from'] = self::sanitize_ymd( isset( $input['md_date_from'] ) ? (string) $input['md_date_from'] : '' );
     336                $out['md_date_to']   = self::sanitize_ymd( isset( $input['md_date_to'] ) ? (string) $input['md_date_to'] : '' );
     337
     338                // Markdown filter: hand-picked page IDs.
     339                $md_pages_in     = isset( $input['md_pages'] ) ? (array) $input['md_pages'] : array();
     340                $out['md_pages'] = array_values( array_unique( array_filter( array_map( 'intval', $md_pages_in ) ) ) );
    322341
    323342                $out['sitemap']         = ! empty( $input['sitemap'] );
    … …  
    331350
    332351                return $out;
     352        }
     353
     354        /**
     355         * Validate a YYYY-MM-DD date, returning '' for anything malformed.
     356         *
     357         * @param string $value Raw input.
     358         * @return string A real calendar date as YYYY-MM-DD, or ''.
     359         */
     360        private static function sanitize_ymd( string $value ): string {
     361                $value = trim( $value );
     362                if ( '' !== $value
     363                        && preg_match( '/^(\d{4})-(\d{2})-(\d{2})$/', $value, $m )
     364                        && checkdate( (int) $m[2], (int) $m[3], (int) $m[1] ) ) {
     365                        return $value;
     366                }
     367                return '';
    333368        }
    334369
    … …  
    371406                }
    372407
     408                $css_path = DISTAN_DIR . 'assets/css/distan-admin.css';
     409                $js_path  = DISTAN_DIR . 'assets/js/distan-admin.js';
     410                $css_ver  = file_exists( $css_path ) ? (string) filemtime( $css_path ) : DISTAN_VERSION;
     411                $js_ver   = file_exists( $js_path ) ? (string) filemtime( $js_path ) : DISTAN_VERSION;
     412
    373413                wp_enqueue_style(
    374414                        'distan-admin',
    375415                        DISTAN_URL . 'assets/css/distan-admin.css',
    376416                        array(),
    377                         DISTAN_VERSION
     417                        $css_ver
    378418                );
    379419
    … …  
    382422                        DISTAN_URL . 'assets/js/distan-admin.js',
    383423                        array(),
    384                         DISTAN_VERSION,
     424                        $js_ver,
    385425                        true
    386426                );
    … …  
    9861026                                                        </td>
    9871027                                                </tr>
     1028                                                <tr id="set-strip-comments">
     1029                                                        <th scope="row"><?php esc_html_e( 'HTMLコメントを削除', 'distan' ); ?></th>
     1030                                                        <td>
     1031                                                                <label>
     1032                                                                        <input type="checkbox" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[strip_comments]" value="1" <?php checked( ! empty( $settings['strip_comments'] ) ); ?>>
     1033                                                                        <?php esc_html_e( '納品HTMLからコメント(<!-- ... -->)を取り除く', 'distan' ); ?>
     1034                                                                </label>
     1035                                                                <p class="description">
     1036                                                                        <?php esc_html_e( 'プラグインやテーマが残す HTML コメントを書き出し時に削除します。<script>・<style>・<textarea>・<pre> の中身は保護し、IE 条件付きコメント(<!--[if ...]>)は中に実マークアップを含みうるため残します。既定オフ。', 'distan' ); ?>
     1037                                                                </p>
     1038                                                        </td>
     1039                                                </tr>
    9881040                                                </table>
    9891041
    … …  
    9931045                                                        <tr id="set-markdown">
    9941046                                                                <th scope="row"><?php esc_html_e( 'Markdown を書き出す', 'distan' ); ?></th>
    995                                                         <td>
     1047                                                        <td x-data="{ mdOn: <?php echo ! empty( $settings['export_markdown'] ) ? 'true' : 'false'; ?>, dfrom: '<?php echo esc_js( (string) $settings['md_date_from'] ); ?>', dto: '<?php echo esc_js( (string) $settings['md_date_to'] ); ?>' }">
    9961048                                                                <label>
    997                                                                         <input type="checkbox" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[export_markdown]" value="1" <?php checked( ! empty( $settings['export_markdown'] ) ); ?>>
     1049                                                                        <input type="checkbox" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[export_markdown]" value="1" @change="mdOn = $event.target.checked" <?php checked( ! empty( $settings['export_markdown'] ) ); ?>>
    9981050                                                                        <?php esc_html_e( 'サイト全体を content.md にまとめる', 'distan' ); ?>
    9991051                                                                </label>
    … …  
    10081060                                                                        <?php esc_html_e( '開発・データ管理用に、URL を置換していない版も出力します。納品物には通常不要です。', 'distan' ); ?>
    10091061                                                                </p>
     1062                                                                <div class="hgp-md-filter" x-show="mdOn" x-cloak>
     1063                                                                        <p class="hgp-md-filter__intro"><?php esc_html_e( 'content.md に含める範囲を絞り込めます。何も指定しなければ従来どおり全ページ(固定ページ・トップ・アーカイブ含む)が対象です。静的サイト(dist/)の生成内容は変わりません。', 'distan' ); ?></p>
     1064
     1065                                                                        <?php
     1066                                                                        $md_types    = array_values( array_filter( Distan_Collector::post_types(), static function ( $t ) { return 'page' !== $t; } ) );
     1067                                                                        $md_selected = (array) $settings['md_post_types'];
     1068                                                                        ?>
     1069                                                                        <?php if ( ! empty( $md_types ) ) : ?>
     1070                                                                                <div class="hgp-md-filter__group">
     1071                                                                                        <div class="hgp-md-filter__head">
     1072                                                                                                <div class="hgp-md-filter__legend"><?php esc_html_e( '投稿タイプ', 'distan' ); ?></div>
     1073                                                                                                <button type="button" class="hgp-md-filter__reset" @click="$refs.ptypes.querySelectorAll( 'input' ).forEach( c =&gt; c.checked = false )"><?php esc_html_e( 'リセット', 'distan' ); ?></button>
     1074                                                                                        </div>
     1075                                                                                        <div class="hgp-md-filter__types" x-ref="ptypes">
     1076                                                                                                <?php foreach ( $md_types as $md_type ) : ?>
     1077                                                                                                        <?php $md_obj = get_post_type_object( $md_type ); ?>
     1078                                                                                                        <label class="hgp-md-filter__type">
     1079                                                                                                                <input type="checkbox" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[md_post_types][]" value="<?php echo esc_attr( $md_type ); ?>" <?php checked( in_array( $md_type, $md_selected, true ) ); ?>>
     1080                                                                                                                <span><?php echo esc_html( $md_obj ? $md_obj->labels->name : $md_type ); ?></span>
     1081                                                                                                                <code class="hgp-md-filter__slug"><?php echo esc_html( $md_type ); ?></code>
     1082                                                                                                        </label>
     1083                                                                                                <?php endforeach; ?>
     1084                                                                                        </div>
     1085                                                                                        <p class="description"><?php esc_html_e( 'チェックしたタイプだけに絞ります(未チェックなら投稿タイプでは絞り込みません)。固定ページは下の個別指定で含めます。', 'distan' ); ?></p>
     1086                                                                                </div>
     1087                                                                        <?php endif; ?>
     1088
     1089                                                                        <div class="hgp-md-filter__group">
     1090                                                                                <div class="hgp-md-filter__head">
     1091                                                                                        <div class="hgp-md-filter__legend"><?php esc_html_e( '公開日(この範囲のみ)', 'distan' ); ?></div>
     1092                                                                                        <button type="button" class="hgp-md-filter__reset" @click="dfrom = ''; dto = ''"><?php esc_html_e( 'リセット', 'distan' ); ?></button>
     1093                                                                                </div>
     1094                                                                                <div class="hgp-md-filter__dates">
     1095                                                                                        <label class="hgp-md-filter__date"><?php esc_html_e( '開始', 'distan' ); ?>
     1096                                                                                                <input type="date" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[md_date_from]" x-model="dfrom" :max="dto || null" value="<?php echo esc_attr( (string) $settings['md_date_from'] ); ?>">
     1097                                                                                        </label>
     1098                                                                                        <span class="hgp-md-filter__dash" aria-hidden="true">〜</span>
     1099                                                                                        <label class="hgp-md-filter__date"><?php esc_html_e( '終了', 'distan' ); ?>
     1100                                                                                                <input type="date" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[md_date_to]" x-model="dto" :min="dfrom || null" value="<?php echo esc_attr( (string) $settings['md_date_to'] ); ?>">
     1101                                                                                        </label>
     1102                                                                                </div>
     1103                                                                                <p class="description hgp-md-filter__warn" x-show="dfrom && dto && dfrom > dto" x-cloak><?php esc_html_e( '開始日が終了日より後になっています。', 'distan' ); ?></p>
     1104                                                                                <p class="description"><?php esc_html_e( '両端を含みます。片方だけの指定も可(例: 開始だけ=その日以降すべて)。固定ページの個別指定はこの日付の影響を受けません。', 'distan' ); ?></p>
     1105                                                                        </div>
     1106
     1107                                                                        <?php
     1108                                                                        $md_page_ids  = get_posts( array( 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'fields' => 'ids' ) );
     1109                                                                        $md_page_list = array();
     1110                                                                        foreach ( (array) $md_page_ids as $md_pid ) {
     1111                                                                                $md_page_list[] = array( 'id' => (int) $md_pid, 'label' => html_entity_decode( get_the_title( (int) $md_pid ), ENT_QUOTES ) . ' (#' . (int) $md_pid . ')' );
     1112                                                                        }
     1113                                                                        $md_picked = array_values( array_unique( array_map( 'intval', (array) $settings['md_pages'] ) ) );
     1114                                                                        ?>
     1115                                                                        <?php if ( ! empty( $md_page_list ) ) : ?>
     1116                                                                                <div class="hgp-md-filter__group" x-data='{ q: "", picks: <?php echo esc_attr( (string) wp_json_encode( $md_picked ) ); ?>, pages: <?php echo esc_attr( (string) wp_json_encode( $md_page_list ) ); ?>, candidates() { const s = this.q.trim().toLowerCase(); return this.pages.filter( p => ! this.picks.includes( p.id ) && ( s === "" || p.label.toLowerCase().includes( s ) ) ); }, add( v ) { const id = parseInt( v, 10 ); if ( id && ! this.picks.includes( id ) ) { this.picks = [ ...this.picks, id ]; } }, remove( id ) { this.picks = this.picks.filter( x => x !== id ); }, labelFor( id ) { const p = this.pages.find( p => p.id === id ); return p ? p.label : ( "#" + id ); } }'>
     1117                                                                                        <div class="hgp-md-filter__head">
     1118                                                                                                <div class="hgp-md-filter__legend"><?php esc_html_e( '固定ページを個別に含める', 'distan' ); ?></div>
     1119                                                                                                <button type="button" class="hgp-md-filter__reset" @click="picks = []; q = ''"><?php esc_html_e( 'リセット', 'distan' ); ?></button>
     1120                                                                                        </div>
     1121                                                                                        <p class="description"><?php esc_html_e( 'ここで選んだ固定ページは、投稿タイプ・公開日の絞り込みに関係なく必ず content.md に入ります。絞り込み中に特定の固定ページだけ含めたいときに使います(トップやアーカイブは対象外)。', 'distan' ); ?></p>
     1122                                                                                        <p class="hgp-template__row">
     1123                                                                                                <label class="screen-reader-text" for="distan-md-page-filter"><?php esc_html_e( 'タイトルで絞り込み', 'distan' ); ?></label>
     1124                                                                                                <input type="search" id="distan-md-page-filter" class="hgp-template__filter" x-model="q" placeholder="<?php esc_attr_e( 'タイトルで絞り込み', 'distan' ); ?>" autocomplete="off">
     1125                                                                                                <label class="screen-reader-text" for="distan-md-page-select"><?php esc_html_e( '追加する固定ページ', 'distan' ); ?></label>
     1126                                                                                                <select id="distan-md-page-select" x-ref="pageSel">
     1127                                                                                                        <template x-for="p in candidates()" :key="p.id">
     1128                                                                                                                <option :value="p.id" x-text="p.label"></option>
     1129                                                                                                        </template>
     1130                                                                                                </select>
     1131                                                                                                <button type="button" class="button" @click="add( $refs.pageSel.value )" :disabled="candidates().length === 0"><?php esc_html_e( '追加', 'distan' ); ?></button>
     1132                                                                                        </p>
     1133                                                                                        <p class="hgp-md-filter__count"><span x-show="q.trim() !== ''" x-cloak><span x-text="candidates().length"></span><?php esc_html_e( ' 件が一致・', 'distan' ); ?></span><span x-text="picks.length"></span><?php esc_html_e( ' 件を選択中', 'distan' ); ?></p>
     1134                                                                                        <div class="hgp-md-filter__chips" x-show="picks.length" x-cloak>
     1135                                                                                                <template x-for="id in picks" :key="'chip-' + id">
     1136                                                                                                        <span class="hgp-md-filter__chip">
     1137                                                                                                                <span x-text="labelFor( id )"></span>
     1138                                                                                                                <button type="button" class="hgp-md-filter__chip-x" @click="remove( id )" :aria-label="'削除: ' + labelFor( id )">&times;</button>
     1139                                                                                                        </span>
     1140                                                                                                </template>
     1141                                                                                        </div>
     1142                                                                                        <template x-for="id in picks" :key="'md-pick-' + id">
     1143                                                                                                <input type="hidden" name="<?php echo esc_attr( Distan::OPTION_KEY ); ?>[md_pages][]" :value="id">
     1144                                                                                        </template>
     1145                                                                                </div>
     1146                                                                        <?php endif; ?>
     1147                                                                </div>
     1148
    10101149                                                        </td>
    10111150                                                </tr>
    … …  
    11771316                                                <dd><?php esc_html_e( 'generator や絵文字などの余分な出力を全ページから省き、納品用に整えます(メタ情報のみ。ブロック用 CSS やプラグイン JS は対象外)。', 'distan' ); ?></dd>
    11781317
     1318                                                <dt><a class="distan-help__jump" href="#set-strip-comments" @click="open = false"><?php esc_html_e( 'HTMLコメントを削除', 'distan' ); ?></a></dt>
     1319                                                <dd><?php esc_html_e( '納品HTMLからプラグインやテーマが残す <!-- ... --> を取り除きます。<script>・<style>・<textarea>・<pre> の中身と IE 条件付きコメントは残します。既定オフ。', 'distan' ); ?></dd>
     1320
    11791321                                                <dt><a class="distan-help__jump" href="#set-markdown" @click="open = false"><?php esc_html_e( 'Markdown を書き出す', 'distan' ); ?></a></dt>
    1180                                                 <dd><?php esc_html_e( '全ページの本文を content.md にまとめます。AI ツールにサイト内容を読ませる用途です。', 'distan' ); ?></dd>
     1322                                                <dd><?php esc_html_e( '全ページの本文を content.md にまとめます。AI ツールにサイト内容を読ませる用途です。投稿タイプ・公開日で対象を絞ったり、固定ページを個別に含めることもできます。', 'distan' ); ?></dd>
    11811323
    11821324                                                <dt><a class="distan-help__jump" href="#set-sitemap" @click="open = false"><?php esc_html_e( 'サイトマップ / robots.txt', 'distan' ); ?></a></dt>
  • distan/trunk/includes/class-distan-cleaner.php

    r3687297 r3690707  
    346346                return (string) apply_filters( 'distan_clean_html', $html );
    347347        }
     348
     349        /**
     350         * Remove plain HTML comments from a finished page (opt-in).
     351         *
     352         * Applied at write time, after Distan_Report::apply_page_markers has
     353         * consumed and removed the distan: markers, so this never races them.
     354         * Comment-like text inside <script>, <style>, <textarea> and <pre> is
     355         * shielded first; IE conditional comments (<!--[if ...]> ... <![endif]-->)
     356         * are kept, because they can wrap real markup and dropping the wrapper
     357         * would silently drop content. Any PCRE failure returns the input
     358         * unchanged rather than risk blanking the page.
     359         *
     360         * @param string $html Finished HTML.
     361         * @return string
     362         */
     363        public static function strip_comments( string $html ): string {
     364                $store = array();
     365
     366                // 1) Shield regions where a comment-like run is content, not a comment.
     367                $protected = preg_replace_callback(
     368                        '~<(script|style|textarea|pre)\b[^>]*>.*?</\1>~is',
     369                        static function ( $m ) use ( &$store ) {
     370                                $store[] = $m[0];
     371                                return "\x00DCMT" . ( count( $store ) - 1 ) . "\x00";
     372                        },
     373                        $html
     374                );
     375                if ( null === $protected ) {
     376                        return $html;
     377                }
     378
     379                // 2) Drop plain comments; keep conditional (<!--[if ...) ones intact.
     380                $cleaned = preg_replace_callback(
     381                        '~<!--(.*?)-->~s',
     382                        static function ( $m ) {
     383                                return 0 === strpos( ltrim( $m[1] ), '[if' ) ? $m[0] : '';
     384                        },
     385                        $protected
     386                );
     387                if ( null === $cleaned ) {
     388                        return $html;
     389                }
     390
     391                // 3) Restore the shielded regions.
     392                $restored = preg_replace_callback(
     393                        '~\x00DCMT(\d+)\x00~',
     394                        static function ( $m ) use ( $store ) {
     395                                $idx = (int) $m[1];
     396                                return isset( $store[ $idx ] ) ? $store[ $idx ] : '';
     397                        },
     398                        $cleaned
     399                );
     400                if ( null === $restored ) {
     401                        return $html;
     402                }
     403
     404                return $restored;
     405        }
    348406}
  • distan/trunk/includes/class-distan-generator.php

    r3687297 r3690707  
    312312                $out_html = Distan_Report::apply_page_markers( $rewritten['html'], $item['path'] );
    313313
     314                if ( ! empty( Distan::settings()['strip_comments'] ) ) {
     315                        $out_html = Distan_Cleaner::strip_comments( $out_html );
     316                }
     317
    314318                if ( ! Distan_Paths::write( $item['path'], $out_html ) ) {
    315319                        return array(
    … …  
    334338
    335339                $section = null;
    336                 if ( ! $is_404 && Distan_Markdown::is_enabled() ) {
     340                if ( ! $is_404 && Distan_Markdown::is_enabled() && Distan_Markdown::wants( $item ) ) {
    337341                        $section = Distan_Markdown::extract( $html, $item );
    338342                }
  • distan/trunk/includes/class-distan-markdown.php

    r3687297 r3690707  
    5050
    5151        /**
     52         * Whether a queue item should be transcribed into the Markdown export.
     53         *
     54         * The static site is always generated in full; this gate narrows only
     55         * content.md, so a site can be delivered whole while the AI-readable
     56         * transcript is limited to (for example) articles within a date window.
     57         *
     58         * Two tracks, both opt-in and both a human declaration:
     59         *   - Post types + publish-date range: bulk selection over article-like
     60         *     types. An empty type list means every type except 'page'.
     61         *   - Hand-picked pages: individual page IDs, always included and never
     62         *     subject to the date filter — an explicit pick is a declaration.
     63         *
     64         * Items with no post type (front page, term archives, the 404 shell) are
     65         * never transcribed: they are navigation, not content.
     66         *
     67         * @param array<string, mixed> $item The queue item (kind, id, post_type, url).
     68         * @return bool
     69         */
     70        public static function wants( array $item ): bool {
     71                $settings = Distan::settings();
     72
     73                // Provenance (kind / id / post_type) lives under 'source', not at the
     74                // top level of the queue item.
     75                $source    = ( isset( $item['source'] ) && is_array( $item['source'] ) ) ? $item['source'] : array();
     76                $id        = isset( $source['id'] ) ? (int) $source['id'] : 0;
     77                $post_type = isset( $source['post_type'] ) ? (string) $source['post_type'] : '';
     78
     79                $pages = array_map( 'intval', (array) ( $settings['md_pages'] ?? array() ) );
     80                $types = array_values( array_filter( array_map( 'strval', (array) ( $settings['md_post_types'] ?? array() ) ) ) );
     81                $from  = (string) ( $settings['md_date_from'] ?? '' );
     82                $to    = (string) ( $settings['md_date_to'] ?? '' );
     83
     84                // Hand-picked pages are always in, whatever the filters — an explicit
     85                // pick is a declaration that overrides everything below.
     86                if ( $id && $pages && in_array( $id, $pages, true ) ) {
     87                        return true;
     88                }
     89
     90                // No filter set at all → the export includes every page, exactly like
     91                // before this feature existed: posts, custom types, fixed pages, the
     92                // front page and archives. Narrowing is entirely opt-in.
     93                $filtering = ( ! empty( $types ) || '' !== $from || '' !== $to );
     94                if ( ! $filtering ) {
     95                        return true;
     96                }
     97
     98                // Narrowing is active. Items with no post type (front page, term
     99                // archives) drop out, and fixed pages come in only through the
     100                // hand-pick list above — a date/type filter is about article-like
     101                // content, and a page is kept by naming it, not by a bulk rule.
     102                if ( '' === $post_type || 'page' === $post_type ) {
     103                        return false;
     104                }
     105
     106                // Post-type filter (empty = every non-page type).
     107                if ( $types && ! in_array( $post_type, $types, true ) ) {
     108                        return false;
     109                }
     110
     111                // Publish-date window, inclusive on both ends. Compared as calendar
     112                // days in the site's timezone, so it matches what an editor sees.
     113                if ( ( '' !== $from || '' !== $to ) && $id ) {
     114                        $date = (string) get_post_time( 'Y-m-d', false, $id );
     115                        if ( '' !== $date ) {
     116                                if ( '' !== $from && $date < $from ) {
     117                                        return false;
     118                                }
     119                                if ( '' !== $to && $date > $to ) {
     120                                        return false;
     121                                }
     122                        }
     123                }
     124
     125                return true;
     126        }
     127
     128        /**
    52129         * Extract one page into a Markdown section.
    53130         *
  • distan/trunk/llms.txt

    r3687297 r3690707  
    1919- 構造化データ(JSON-LD)の保持と URL 置換(生成はしない。SEO プラグインの出力を運ぶ)
    2020- クリーン HTML(WordPress の痕跡除去、noindex 除去)
     21- HTMLコメント削除(strip_comments・既定オフ): 納品HTMLからプレーンな`<!-- -->`を除去。apply_page_markers後・書き出し直前に適用(distan:マーカーと競合しない)。script/style/textarea/pre内は保護、IE条件付きコメント(<!--[if)は残す。PCRE失敗時は無変更で返す
    2122- パス平坦化(テーマ→assets/、uploads→media/)
    2223- キャッシュバスティングのクエリ保持(ファイル名不変で FTP 上書き可)
    … …  
    2425- 大きいファイルの検出と警告(バイナリはストリームコピー、一定サイズ超はレポートに一覧。既定 10MB、distan_large_file_threshold で変更可。コピーはするので手作業不要)
    2526- Markdown 書き出し(選択制、content.md、Gemini Notebook(旧NotebookLM)等の AI ツール向け)
     27  - 絞り込み(Distan_Markdown::wants): 何も指定しなければ全ページ(投稿・CPT・固定ページ・トップ・アーカイブ=1.7同等 full export)。フィルタ設定時のみ絞り込み——投稿タイプ(md_post_types・チェックしたタイプだけ)/公開日(md_date_from〜md_date_to・両端含む)で限定し、絞込中はトップ/アーカイブ/固定ページが外れる。個別の固定ページ(md_pages・検索+セレクト+「追加」でチップ選択・テンプレート書き出しと同UI)は絞込に関係なく常に採用。静的サイト(dist/)は不変(content.md 側だけのゲート)
    2628  - Markdown書き出し: 表→パイプ表・pre/code→フェンス/バッククォート・img→![alt]・blockquote→>・strong/em→**/*・ol→番号・hr→---。各セクションにtitle/URL/description。titleは<title>→本文h1→URLの順でフォールバック、本文先頭の重複見出しは除去。TOCは逐次書き出し設計と衝突のため未実装
    2729- サイトマップ書き出し(選択制、sitemap.xml、Google Search Console 対応。著者・日付アーカイブは載せないので ID 露出なし。スラッグ以下や語を含む URL を除外可)
  • distan/trunk/readme.txt

    r3687297 r3690707  
    55Tested up to: 7.1
    66Requires PHP: 8.0
    7 Stable tag: 1.7.0
     7Stable tag: 1.8.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    8181= Can I export the content for AI tools? =
    8282
    83 Yes. Enable the Markdown export and Distan writes `content.md`, combining every page's main content into one file with production URLs — ready to hand to an AI notebook or a retrieval index. An optional `content.local.md` keeps development URLs.
     83Yes. Enable the Markdown export and Distan writes `content.md`, combining every page's main content into one file with production URLs — ready to hand to an AI notebook or a retrieval index. An optional `content.local.md` keeps development URLs. You can also narrow what goes into it by post type and publish date, and hand-pick individual fixed pages, so the transcript can be limited to (for example) just your articles while the static site is still delivered in full.
    8484
    8585= Can I open the generated files directly? =
    … …  
    101101
    102102== Changelog ==
     103
     104= 1.8.0 =
     105* Added: the Markdown export (content.md) can now be narrowed by post type and by publish date, and specific fixed pages can be force-included, so a site can be delivered whole while only, say, its articles within a date window are transcribed for an AI. With no filter set the export still covers every page as before (posts, custom types, fixed pages, the front page and archives). When you do filter, post types are chosen with checkboxes and the publish-date range is inclusive on both ends (either bound may be left open); while filtering, pages and archives drop out unless a page is added individually from the live title search, which force-includes it. The static HTML output (dist/) is unchanged by any of this.
     106* Added: an optional "remove HTML comments" setting. When enabled, plain HTML comments (<!-- ... -->) left by plugins and themes are stripped from the delivered pages at write time. Comment-like text inside <script>, <style>, <textarea> and <pre> is shielded, and IE conditional comments (<!--[if ...]>) are kept because they can wrap real markup. Off by default; the static output is unchanged unless you turn it on.
     107* Changed: the admin screen's own styles and scripts are now cache-busted by file modification time, so an updated build always loads its current assets instead of a stale cached copy.
    103108
    104109= 1.7.0 =
Note: See TracChangeset for help on using the changeset viewer.