Skip to content

feat: add sub-query / sub-item blocks for related-post expansion within items (#11)#12

Merged
mt8 merged 1 commit intomainfrom
feature/11-sub-query
Apr 28, 2026
Merged

feat: add sub-query / sub-item blocks for related-post expansion within items (#11)#12
mt8 merged 1 commit intomainfrom
feature/11-sub-query

Conversation

@mt8
Copy link
Copy Markdown
Owner

@mt8 mt8 commented Apr 28, 2026

Closes #11.

Summary

  • 新ブロック feedwright/sub-query / feedwright/sub-item を追加。<item> テンプレートの中で関連投稿を N 件まで取得し、サブテンプレートを兄弟ノードとして展開できるようになった。goo smp:relation、mediba mdf:relatedLink、Google Merchant g:additional_image_link 等の「item ごとの関連リンク」パターンに対応。
  • relationMode は taxonomy(階層型タクソノミー限定)manual(ID 列指定) の 2 種類。issue item 内サブクエリ:関連投稿を <item> ごとに展開できるブロックを追加 #11 起案時にあった meta_key モードは利用イメージと違ったため削除済み(フラットタクソノミーも同様の理由で除外)。
  • Renderer\Contextwith_post() immutable パターンをそのまま活用し、サブクエリ内のバインディングは関連投稿側で解決、兄弟要素に戻ると元の item の投稿に戻る(呼び出しチェーン=コンテキストスタック)。
  • 件数のスペック上限(goo 3 / mediba 5 / Merchant 10 等)は feedwright/sub_query/hard_max フィルタで強制可能。

アーキ変更点

  • ElementRenderer::render_child() の戻り値を ?\DOMNodearray<\DOMNode> に変更。1 ブロック = 1 ノードという前提を外し、サブクエリのように複数ノードを返すブロックに対応。ItemQueryRenderer と element の children モードも iterate に統一。
  • ArgsBuilder::build_sub( array $attrs, WP_Post $current ): ?array を追加。taxonomy モードは is_taxonomy_hierarchical() で防御し、フラットタクソノミーや term の無い投稿は null を返してサブクエリをスキップ。
  • SubQueryRenderer を新設。outer item ごとに 1 回 WP_Query を発行(N+1)、update_post_meta_cache=falseRenderCache で吸収。

Test plan

  • Editor: feed 投稿の <item> 内で Sub Query ブロックが追加でき、Inspector の Match by に Same taxonomy term (hierarchical only) / Manual ID list の 2 択のみが出る。Taxonomy セレクタには階層型のみ(Tags は除外)が出る。
  • Render: goo フィード(http://localhost:9888/?feedwright_feed_slug=goonews)の各 <item> 配下に最大 3 件の <smp:relation> が出力され、現投稿は除外される。
  • Wrapper パターン: <smp:relations> のような 1 個のラッパ要素の中に sub-query を入れ子にした場合、ラッパ 1 + 子 N の形で出力される。
  • Hard cap: feedwright/sub_query/hard_max フィルタで return 1; すると、各 item の関連が 1 件に制限される。
  • Skip 挙動: フラットタクソノミー(post_tag)を選んでも 0 件で安全にスキップ。
  • Tests: composer test:unit (57 passed), wp-env tests (98 passed), composer phpcs (28 passed)。
  • i18n: ja 翻訳 .po/.mo/.json を更新済み。

ドキュメント

  • docs/requirements.md §12.6.1 / §12.6.2 / §13.6.1 にサブクエリ仕様を追記。

…in items (#11)

Introduce two new blocks that let an item template expand related posts
into N sibling DOM nodes per outer item, covering aggregator specs that
require per-item related links (goo smp:relation, mediba mdf:relatedLink,
Google Merchant g:additional_image_link, ...).

- feedwright/sub-query: ancestor=item, two relation modes:
  - taxonomy: posts sharing a hierarchical taxonomy term with the
    current item (flat taxonomies skipped — exact-term matches are
    noise on user-typed free input)
  - manual: post__in against an explicit ID list, order preserved
- feedwright/sub-item: parent=sub-query, holds the inner element template
- ArgsBuilder::build_sub builds the per-item WP_Query args, scoped by
  the current item's terms or the manual ID list
- SubQueryRenderer iterates the sub-query and renders the sub-item
  template against a context whose current_post is the related post
- ElementRenderer::render_child now returns array<DOMNode> so a single
  child block can expand to many sibling nodes; ItemQueryRenderer and
  the children-mode element branch updated to iterate
- feedwright/sub_query/hard_max filter caps results per outer item to
  enforce spec-mandated limits (e.g. 3 / 5 / 10)
- Tests cover taxonomy / manual modes, hard-cap filter, flat-taxonomy
  skip behavior, and degraded behavior outside item scope
@mt8 mt8 merged commit dd9d03a into main Apr 28, 2026
7 checks passed
@mt8 mt8 deleted the feature/11-sub-query branch April 28, 2026 00:44
@mt8 mt8 mentioned this pull request Apr 28, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

item 内サブクエリ:関連投稿を <item> ごとに展開できるブロックを追加

1 participant