feat(portal): docs/16 首页布局后端- home_layout零DDL消费与主题fragment化-PortalSiteSnapshot.homeLayout+normalizeHomeLayout脏数据容错;PortalPageRenderer.buildLayoutBlocks按区块序列渲染(article_list多栏目聚合+homeStyle别名+category合成+background回落news_bg_image/ticker top|category双源/gallery标题副题缺省旧键/links分组过滤/visible跳过/未知type跳过/size 1~20夹取);布局模式清空topArticles/focusArticles/categoryBlocks/galleryBanners回落段;SiteService.validateConfigJson带siteId收紧home_layout(blocks<=30/type白名单/size 1~20/文本<=100/categoryIds归属校验:新建拒跨站拒不存在拒);themes/common/fragments/home-blocks.html plb-*兜底骨架(不注册皮肤包,Thymeleaf classpath可解析);campus-glow自有fragment(news_grid/media_focus/card/ticker/gallery)原home.html抽出;default+blue-white+classic-red+fresh-mint+mint-breeze+warm-kinder+scholar-blue+campus-glow八套home.html接入布局分支(th:case父元素+th:replace子元素嵌套,replace优先级100先于case执行);新增PortalHomeLayoutIT 5+SiteServiceHomeLayoutIT 3,全量330绿
build / build-push (push) Successful in 52s

This commit is contained in:
chenxing
2026-09-10 15:08:40 +08:00
parent 98d640faba
commit 39454e4efb
15 changed files with 1233 additions and 143 deletions
@@ -0,0 +1,150 @@
<!--
campus-glow 主题首页区块 fragment(docs/16 §4.4 fragment 化):
news_grid/media_focus/card 三形态由原 home.html 内联段抽出(标记与样式不变,主题 main.css 继续承载);
ticker/gallery 为布局模式专用 fragment(回落模式仍走 home.html 原内联段,数据源 topArticles/galleryBanners)。
契约:块字段与回落 categoryBlocks 同构(category.name 取标题);布局块 background 为 Boolean
开关(未设时回退旧键 news_bg_image 无条件生效),布局块 category.name=区块标题。
-->
<!-- 形态一:双栏新闻卡(homeStyle=news_grid)——全幅背景 + 毛玻璃卡 + 双栏日期列表
(background 为布局块可选键,回落块无此键——SpEL 对 Map 缺失键点号访问会抛错,用 ['key'] 括号形式) -->
<section class="cg-newshot" th:fragment="news_grid(block)" aria-label="栏目区块"
th:with="newsBg=${block['background'] != null ? (block['background'] ? site.config['news_bg_image'] : null) : site.config['news_bg_image']}">
<div class="cg-newshot-bg" th:if="${!#strings.isEmpty(newsBg)}"
th:style="|background-image:url(${url.upload(newsBg)})|"></div>
<div class="cg-container">
<div class="cg-newshot-card">
<div class="cg-sec-head">
<h2 th:text="${block.category.name}">校园时讯</h2>
<a class="cg-more-circle" th:href="${block.moreUrl}" aria-label="更多">
<svg viewBox="0 0 24 24" width="18" height="18" focusable="false" aria-hidden="true">
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" d="M5 12h14M13 6l6 6-6 6"/>
</svg>
</a>
</div>
<ul class="cg-news-grid" th:if="${!#lists.isEmpty(block.items)}">
<li th:each="item : ${block.items}">
<span class="cg-news-date" th:if="${item.publishTime != null}"
th:text="${#temporals.format(item.publishTime, 'MM-dd')}">09-09</span>
<a class="cg-news-title" th:href="${url.article(item.id)}" th:text="${item.title}">文章标题</a>
<span class="cg-top-badge" th:if="${item.topmost == 1}">置顶</span>
</li>
</ul>
<div class="cg-empty" th:if="${#lists.isEmpty(block.items)}">
<p>栏目暂无内容</p>
<p class="cg-empty-hint">内容发布后将在此展示</p>
</div>
</div>
</div>
</section>
<!-- 形态二:媒体聚焦列表(homeStyle=media_focus)——来源徽标 + 标题双栏 -->
<section class="cg-media" th:fragment="media_focus(block)" aria-label="栏目区块">
<div class="cg-container">
<div class="cg-media-card">
<div class="cg-sec-head">
<h2 th:text="${block.category.name}">媒体聚焦</h2>
<a class="cg-more-circle" th:href="${block.moreUrl}" aria-label="更多">
<svg viewBox="0 0 24 24" width="18" height="18" focusable="false" aria-hidden="true">
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" d="M5 12h14M13 6l6 6-6 6"/>
</svg>
</a>
</div>
<ul class="cg-media-grid" th:if="${!#lists.isEmpty(block.items)}">
<li th:each="item : ${block.items}">
<span class="cg-source-badge" th:if="${!#strings.isEmpty(item.source)}"
th:text="${item.source}">媒体来源</span>
<a class="cg-media-title" th:href="${url.article(item.id)}" th:text="${item.title}">文章标题</a>
<span class="cg-top-badge" th:if="${item.topmost == 1}">置顶</span>
</li>
</ul>
<div class="cg-empty" th:if="${#lists.isEmpty(block.items)}">
<p>栏目暂无内容</p>
<p class="cg-empty-hint">内容发布后将在此展示</p>
</div>
</div>
</div>
</section>
<!-- 形态三:默认卡(featured 首条 + 行式列表) -->
<section class="cg-block" th:fragment="card(block)" aria-label="栏目区块">
<div class="cg-container">
<div class="cg-block-card">
<div class="cg-sec-head">
<h2 th:text="${block.category.name}">栏目名</h2>
<a class="cg-more-text" th:href="${block.moreUrl}">更多 &gt;</a>
</div>
<div class="cg-block-cols" th:if="${!#lists.isEmpty(block.items)}">
<a class="cg-block-featured" th:with="feat=${block.items[0]}" th:href="${url.article(feat.id)}">
<span class="cg-feat-cover" th:if="${feat.coverImage != null}">
<img th:src="${url.upload(feat.coverImage)}" th:alt="${feat.title}">
</span>
<span class="cg-feat-body">
<span class="cg-feat-title" th:text="${feat.title}">头条标题</span>
<span class="cg-feat-summary" th:if="${!#strings.isEmpty(feat.summary)}"
th:text="${feat.summary}">摘要</span>
<span class="cg-feat-meta">
<time th:if="${feat.publishTime != null}"
th:text="${#temporals.format(feat.publishTime, 'yyyy-MM-dd')}">2026-01-01</time>
</span>
</span>
</a>
<ul class="cg-block-list">
<li th:each="item, stat : ${block.items}" th:if="${stat.index > 0}">
<a th:href="${url.article(item.id)}" th:text="${item.title}">文章标题</a>
<time th:if="${item.publishTime != null}"
th:text="${#temporals.format(item.publishTime, 'MM-dd')}">01-01</time>
</li>
</ul>
</div>
<div class="cg-empty" th:if="${#lists.isEmpty(block.items)}">
<p>栏目暂无内容</p>
<p class="cg-empty-hint">内容发布后将在此展示</p>
</div>
</div>
</div>
</section>
<!-- 布局模式:滚动速递(数据=渲染端装配进 block.items) -->
<section class="cg-ticker" th:fragment="ticker(block)" aria-label="要闻速递" th:if="${!#lists.isEmpty(block.items)}">
<div class="cg-container cg-ticker-inner">
<span class="cg-ticker-label" th:text="${block.title}">要闻速递</span>
<div class="cg-ticker-viewport">
<div class="cg-ticker-track">
<a class="cg-ticker-item" th:each="item : ${block.items}" th:href="${url.article(item.id)}">
<span class="cg-ticker-dot" aria-hidden="true"></span>
<span th:text="${item.title}">要闻标题</span>
</a>
<a class="cg-ticker-item" th:each="item : ${block.items}" th:href="${url.article(item.id)}" aria-hidden="true">
<span class="cg-ticker-dot" aria-hidden="true"></span>
<span th:text="${item.title}">要闻标题</span>
</a>
</div>
</div>
</div>
</section>
<!-- 布局模式:线上展厅(数据=block.items 轮播位 gallery;标题/副题=渲染端已合并旧键缺省) -->
<section class="cg-gallery" th:fragment="gallery(block)" aria-label="线上展厅" th:if="${!#lists.isEmpty(block.items)}">
<div class="cg-container">
<div class="cg-gallery-head">
<h2 th:text="${block.title}">线上展厅</h2>
<p class="cg-gallery-sub" th:text="${block.subtitle}">Online Exhibition Hall</p>
</div>
<div class="cg-gallery-stage"
th:classappend="${'cg-gallery-cols-' + (themeParams['galleryCols'] ?: '4')}"
th:attr="data-cols=${themeParams['galleryCols'] ?: '4'}">
<div class="cg-gallery-track">
<a class="cg-gallery-item" th:each="g : ${block.items}" th:href="${g.linkUrl}"
th:title="${g.title}">
<img th:src="${g.imageUrl}" th:alt="${g.title}">
<span class="cg-gallery-cap" th:if="${!#strings.isEmpty(g.title)}"
th:text="${g.title}">作品标题</span>
</a>
</div>
<button class="cg-gallery-arrow prev" type="button" aria-label="上一页" th:if="${#lists.size(block.items) > 1}">‹</button>
<button class="cg-gallery-arrow next" type="button" aria-label="下一页" th:if="${#lists.size(block.items) > 1}">›</button>
</div>
</div>
</section>
@@ -5,7 +5,7 @@
<header th:replace="~{${themeBase} + '/fragments/header' :: header}"></header>
<main class="cg-home" id="main-content">
<!-- 首页轮播位(cms_banner position=home;设计尺寸 1920×560,见 theme.json bannerSize) -->
<!-- 首页轮播位(cms_banner position=home;设计尺寸 1920×560,见 theme.json bannerSize)——页面级固定槽位,布局模式同样保留 -->
<section class="cg-banner" th:if="${!#lists.isEmpty(banners)}" aria-label="焦点图片">
<div class="cg-banner-slides">
<a class="cg-banner-slide" th:each="b, stat : ${banners}"
@@ -23,151 +23,81 @@
</div>
</section>
<!-- 要闻速递横条:置顶文章横向无缝滚动(hover 暂停) -->
<section class="cg-ticker" th:if="${!#lists.isEmpty(topArticles)}" aria-label="要闻速递">
<div class="cg-container cg-ticker-inner">
<span class="cg-ticker-label">要闻速递</span>
<div class="cg-ticker-viewport">
<div class="cg-ticker-track">
<a class="cg-ticker-item" th:each="item : ${topArticles}" th:href="${url.article(item.id)}">
<span class="cg-ticker-dot" aria-hidden="true"></span>
<span th:text="${item.title}">要闻标题</span>
</a>
<a class="cg-ticker-item" th:each="item : ${topArticles}" th:href="${url.article(item.id)}" aria-hidden="true">
<span class="cg-ticker-dot" aria-hidden="true"></span>
<span th:text="${item.title}">要闻标题</span>
</a>
</div>
</div>
</div>
</section>
<!-- 首页布局模式(docs/16 §4.4):home_layout 落库后按区块序列渲染。
article_list 三种形态走主题自有 fragment(compact/image_wall 与未实现类型落 common 兜底骨架)。
注意:th:replace(优先级100)先于 th:case(300)执行——case 必须放父元素、replace 放子元素 -->
<th:block th:if="${layoutBlocks != null}" th:each="block : ${layoutBlocks}">
<th:block th:switch="${block.type}">
<th:block th:case="'article_list'">
<th:block th:switch="${block.homeStyle}">
<th:block th:case="'news_grid'"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: news_grid(${block})}" /></th:block>
<th:block th:case="'media_focus'"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: media_focus(${block})}" /></th:block>
<th:block th:case="'compact'"><th:block th:replace="~{'themes/common/fragments/home-blocks' :: plbCompact(${block})}" /></th:block>
<th:block th:case="'image_wall'"><th:block th:replace="~{'themes/common/fragments/home-blocks' :: plbImageWall(${block})}" /></th:block>
<th:block th:case="*"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: card(${block})}" /></th:block>
</th:block>
</th:block>
<th:block th:case="'ticker'"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: ticker(${block})}" /></th:block>
<th:block th:case="'gallery'"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: gallery(${block})}" /></th:block>
<th:block th:case="'links'"><th:block th:replace="~{'themes/common/fragments/home-blocks' :: plbLinks(${block})}" /></th:block>
<th:block th:case="*"><th:block th:replace="~{'themes/common/fragments/home-blocks' :: render(${block})}" /></th:block>
</th:block>
</th:block>
<!-- 一级栏目区块(docs/12):按栏目 homeStyle 三种形态渲染,栏目顺序即首页板块顺序 -->
<th:block th:each="block : ${categoryBlocks}">
<!-- 形态一:双栏新闻卡(homeStyle=news_grid)——全幅背景 + 毛玻璃卡 + 双栏日期列表 -->
<section class="cg-newshot" th:if="${block.homeStyle == 'news_grid'}"
th:with="newsBg=${site.config['news_bg_image']}" aria-label="栏目区块">
<div class="cg-newshot-bg" th:if="${!#strings.isEmpty(newsBg)}"
th:style="|background-image:url(${url.upload(newsBg)})|"></div>
<div class="cg-container">
<div class="cg-newshot-card">
<div class="cg-sec-head">
<h2 th:text="${block.category.name}">校园时讯</h2>
<a class="cg-more-circle" th:href="${block.moreUrl}" aria-label="更多">
<svg viewBox="0 0 24 24" width="18" height="18" focusable="false" aria-hidden="true">
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" d="M5 12h14M13 6l6 6-6 6"/>
</svg>
<!-- 回落分支(docs/16 D2):无 home_layout 时按现状渲染(布局模式下渲染端数据源已清空,双保险不漏段) -->
<th:block th:unless="${layoutBlocks != null}">
<!-- 要闻速递横条:置顶文章横向无缝滚动(hover 暂停) -->
<section class="cg-ticker" th:if="${!#lists.isEmpty(topArticles)}" aria-label="要闻速递">
<div class="cg-container cg-ticker-inner">
<span class="cg-ticker-label">要闻速递</span>
<div class="cg-ticker-viewport">
<div class="cg-ticker-track">
<a class="cg-ticker-item" th:each="item : ${topArticles}" th:href="${url.article(item.id)}">
<span class="cg-ticker-dot" aria-hidden="true"></span>
<span th:text="${item.title}">要闻标题</span>
</a>
<a class="cg-ticker-item" th:each="item : ${topArticles}" th:href="${url.article(item.id)}" aria-hidden="true">
<span class="cg-ticker-dot" aria-hidden="true"></span>
<span th:text="${item.title}">要闻标题</span>
</a>
</div>
<ul class="cg-news-grid" th:if="${!#lists.isEmpty(block.items)}">
<li th:each="item : ${block.items}">
<span class="cg-news-date" th:if="${item.publishTime != null}"
th:text="${#temporals.format(item.publishTime, 'MM-dd')}">09-09</span>
<a class="cg-news-title" th:href="${url.article(item.id)}" th:text="${item.title}">文章标题</a>
<span class="cg-top-badge" th:if="${item.topmost == 1}">置顶</span>
</li>
</ul>
<div class="cg-empty" th:if="${#lists.isEmpty(block.items)}">
<p>栏目暂无内容</p>
<p class="cg-empty-hint">内容发布后将在此展示</p>
</div>
</div>
</div>
</section>
<!-- 形态二:媒体聚焦列表(homeStyle=media_focus)——来源徽标 + 标题双栏 -->
<section class="cg-media" th:if="${block.homeStyle == 'media_focus'}" aria-label="栏目区块">
<div class="cg-container">
<div class="cg-media-card">
<div class="cg-sec-head">
<h2 th:text="${block.category.name}">媒体聚焦</h2>
<a class="cg-more-circle" th:href="${block.moreUrl}" aria-label="更多">
<svg viewBox="0 0 24 24" width="18" height="18" focusable="false" aria-hidden="true">
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" d="M5 12h14M13 6l6 6-6 6"/>
</svg>
</a>
</div>
<ul class="cg-media-grid" th:if="${!#lists.isEmpty(block.items)}">
<li th:each="item : ${block.items}">
<span class="cg-source-badge" th:if="${!#strings.isEmpty(item.source)}"
th:text="${item.source}">媒体来源</span>
<a class="cg-media-title" th:href="${url.article(item.id)}" th:text="${item.title}">文章标题</a>
<span class="cg-top-badge" th:if="${item.topmost == 1}">置顶</span>
</li>
</ul>
<div class="cg-empty" th:if="${#lists.isEmpty(block.items)}">
<p>栏目暂无内容</p>
<p class="cg-empty-hint">内容发布后将在此展示</p>
</div>
</div>
</div>
</section>
<!-- 一级栏目区块(docs/12):按栏目 homeStyle 三种形态渲染,栏目顺序即首页板块顺序 -->
<th:block th:each="block : ${categoryBlocks}">
<th:block th:switch="${block.homeStyle}">
<th:block th:case="'news_grid'"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: news_grid(${block})}" /></th:block>
<th:block th:case="'media_focus'"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: media_focus(${block})}" /></th:block>
<th:block th:case="*"><th:block th:replace="~{${themeBase} + '/fragments/home-blocks' :: card(${block})}" /></th:block>
</th:block>
</th:block>
<!-- 形态三:默认卡(homeStyle 空)——featured 首条 + 行式列表,旧栏目保持常规呈现 -->
<section class="cg-block" th:if="${block.homeStyle == null or block.homeStyle == ''}" aria-label="栏目区块">
<!-- 线上展厅(cms_banner position=gallery;设计尺寸 800×520;每行列数由主题参数 galleryCols 控制) -->
<section class="cg-gallery" th:if="${!#lists.isEmpty(galleryBanners)}" aria-label="线上展厅">
<div class="cg-container">
<div class="cg-block-card">
<div class="cg-sec-head">
<h2 th:text="${block.category.name}">栏目名</h2>
<a class="cg-more-text" th:href="${block.moreUrl}">更多 &gt;</a>
</div>
<div class="cg-block-cols" th:if="${!#lists.isEmpty(block.items)}">
<a class="cg-block-featured" th:with="feat=${block.items[0]}" th:href="${url.article(feat.id)}">
<span class="cg-feat-cover" th:if="${feat.coverImage != null}">
<img th:src="${url.upload(feat.coverImage)}" th:alt="${feat.title}">
</span>
<span class="cg-feat-body">
<span class="cg-feat-title" th:text="${feat.title}">头条标题</span>
<span class="cg-feat-summary" th:if="${!#strings.isEmpty(feat.summary)}"
th:text="${feat.summary}">摘要</span>
<span class="cg-feat-meta">
<time th:if="${feat.publishTime != null}"
th:text="${#temporals.format(feat.publishTime, 'yyyy-MM-dd')}">2026-01-01</time>
</span>
</span>
<div class="cg-gallery-head">
<h2 th:text="${site.config['gallery_title'] ?: '线上展厅'}">线上展厅</h2>
<p class="cg-gallery-sub" th:text="${site.config['gallery_subtitle'] ?: 'Online Exhibition Hall'}">Online Exhibition Hall</p>
</div>
<div class="cg-gallery-stage"
th:classappend="${'cg-gallery-cols-' + (themeParams['galleryCols'] ?: '4')}"
th:attr="data-cols=${themeParams['galleryCols'] ?: '4'}">
<div class="cg-gallery-track">
<a class="cg-gallery-item" th:each="g : ${galleryBanners}" th:href="${g.linkUrl}"
th:title="${g.title}">
<img th:src="${g.imageUrl}" th:alt="${g.title}">
<span class="cg-gallery-cap" th:if="${!#strings.isEmpty(g.title)}"
th:text="${g.title}">作品标题</span>
</a>
<ul class="cg-block-list">
<li th:each="item, stat : ${block.items}" th:if="${stat.index > 0}">
<a th:href="${url.article(item.id)}" th:text="${item.title}">文章标题</a>
<time th:if="${item.publishTime != null}"
th:text="${#temporals.format(item.publishTime, 'MM-dd')}">01-01</time>
</li>
</ul>
</div>
<div class="cg-empty" th:if="${#lists.isEmpty(block.items)}">
<p>栏目暂无内容</p>
<p class="cg-empty-hint">内容发布后将在此展示</p>
</div>
<button class="cg-gallery-arrow prev" type="button" aria-label="上一页" th:if="${#lists.size(galleryBanners) > 1}">‹</button>
<button class="cg-gallery-arrow next" type="button" aria-label="下一页" th:if="${#lists.size(galleryBanners) > 1}">›</button>
</div>
</div>
</section>
</th:block>
<!-- 线上展厅(cms_banner position=gallery;设计尺寸 800×520;每行列数由主题参数 galleryCols 控制) -->
<section class="cg-gallery" th:if="${!#lists.isEmpty(galleryBanners)}" aria-label="线上展厅">
<div class="cg-container">
<div class="cg-gallery-head">
<h2 th:text="${site.config['gallery_title'] ?: '线上展厅'}">线上展厅</h2>
<p class="cg-gallery-sub" th:text="${site.config['gallery_subtitle'] ?: 'Online Exhibition Hall'}">Online Exhibition Hall</p>
</div>
<div class="cg-gallery-stage"
th:classappend="${'cg-gallery-cols-' + (themeParams['galleryCols'] ?: '4')}"
th:attr="data-cols=${themeParams['galleryCols'] ?: '4'}">
<div class="cg-gallery-track">
<a class="cg-gallery-item" th:each="g : ${galleryBanners}" th:href="${g.linkUrl}"
th:title="${g.title}">
<img th:src="${g.imageUrl}" th:alt="${g.title}">
<span class="cg-gallery-cap" th:if="${!#strings.isEmpty(g.title)}"
th:text="${g.title}">作品标题</span>
</a>
</div>
<button class="cg-gallery-arrow prev" type="button" aria-label="上一页" th:if="${#lists.size(galleryBanners) > 1}">‹</button>
<button class="cg-gallery-arrow next" type="button" aria-label="下一页" th:if="${#lists.size(galleryBanners) > 1}">›</button>
</div>
</div>
</section>
</main>
<footer th:replace="~{${themeBase} + '/fragments/footer' :: footer}"></footer>