feat: add sub-query / sub-item blocks for related-post expansion within items (#11)#12
Merged
feat: add sub-query / sub-item blocks for related-post expansion within items (#11)#12
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11.
Summary
feedwright/sub-query/feedwright/sub-itemを追加。<item>テンプレートの中で関連投稿を N 件まで取得し、サブテンプレートを兄弟ノードとして展開できるようになった。goosmp:relation、medibamdf:relatedLink、Google Merchantg:additional_image_link等の「item ごとの関連リンク」パターンに対応。taxonomy(階層型タクソノミー限定) とmanual(ID 列指定) の 2 種類。issue item 内サブクエリ:関連投稿を <item> ごとに展開できるブロックを追加 #11 起案時にあったmeta_keyモードは利用イメージと違ったため削除済み(フラットタクソノミーも同様の理由で除外)。Renderer\Contextのwith_post()immutable パターンをそのまま活用し、サブクエリ内のバインディングは関連投稿側で解決、兄弟要素に戻ると元の item の投稿に戻る(呼び出しチェーン=コンテキストスタック)。feedwright/sub_query/hard_maxフィルタで強制可能。アーキ変更点
ElementRenderer::render_child()の戻り値を?\DOMNode→array<\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=false+RenderCacheで吸収。Test plan
<item>内で Sub Query ブロックが追加でき、Inspector の Match by にSame taxonomy term (hierarchical only)/Manual ID listの 2 択のみが出る。Taxonomy セレクタには階層型のみ(Tags は除外)が出る。<item>配下に最大 3 件の<smp:relation>が出力され、現投稿は除外される。<smp:relations>のような 1 個のラッパ要素の中に sub-query を入れ子にした場合、ラッパ 1 + 子 N の形で出力される。feedwright/sub_query/hard_maxフィルタでreturn 1;すると、各 item の関連が 1 件に制限される。composer test:unit(57 passed), wp-env tests (98 passed),composer phpcs(28 passed)。.po/.mo/.jsonを更新済み。ドキュメント
docs/requirements.md§12.6.1 / §12.6.2 / §13.6.1 にサブクエリ仕様を追記。