feat: support custom post password template. (#1236)

pull/1237/head^2
Ryan Wang 2021-01-24 14:50:24 +08:00 committed by GitHub
parent 042e72f224
commit 8bb416db1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 38 deletions

View File

@ -75,7 +75,10 @@ public class PostModel {
if (post.getStatus().equals(PostStatus.INTIMATE) && StringUtils.isEmpty(token)) { if (post.getStatus().equals(PostStatus.INTIMATE) && StringUtils.isEmpty(token)) {
model.addAttribute("slug", post.getSlug()); model.addAttribute("slug", post.getSlug());
return "common/template/post_password"; if (themeService.templateExists(HaloConst.POST_PASSWORD_TEMPLATE + HaloConst.SUFFIX_FTL)) {
return themeService.render(HaloConst.POST_PASSWORD_TEMPLATE);
}
return "common/template/" + HaloConst.POST_PASSWORD_TEMPLATE;
} }
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {

View File

@ -46,11 +46,6 @@ public class HaloConst {
*/ */
public final static String HALO_DATA_EXPORT_PREFIX = "halo-data-export-"; public final static String HALO_DATA_EXPORT_PREFIX = "halo-data-export-";
/**
* Static pages pack prefix.
*/
public final static String STATIC_PAGE_PACK_PREFIX = "static-pages-";
/** /**
* Default theme name. * Default theme name.
*/ */
@ -65,6 +60,11 @@ public class HaloConst {
* Path separator. * Path separator.
*/ */
public static final String FILE_SEPARATOR = File.separator; public static final String FILE_SEPARATOR = File.separator;
/**
* Post password template name.
*/
public static final String POST_PASSWORD_TEMPLATE = "post_password";
/** /**
* Suffix of freemarker template file * Suffix of freemarker template file
*/ */

View File

@ -165,6 +165,7 @@ public class ThemeServiceImpl implements ThemeService {
Path themePath = Paths.get(themeProperty.getThemePath()); Path themePath = Paths.get(themeProperty.getThemePath());
try (Stream<Path> pathStream = Files.list(themePath)) { try (Stream<Path> pathStream = Files.list(themePath)) {
return pathStream.filter(path -> StringUtils.startsWithIgnoreCase(path.getFileName().toString(), prefix)) return pathStream.filter(path -> StringUtils.startsWithIgnoreCase(path.getFileName().toString(), prefix))
.filter(path -> !(HaloConst.POST_PASSWORD_TEMPLATE + HaloConst.SUFFIX_FTL).equals(path.getFileName().toString()))
.map(path -> { .map(path -> {
// Remove prefix // Remove prefix
String customTemplate = StringUtils.removeStartIgnoreCase(path.getFileName().toString(), prefix); String customTemplate = StringUtils.removeStartIgnoreCase(path.getFileName().toString(), prefix);

View File

@ -1,32 +0,0 @@
<div style="text-align:center">
<img src="${user.avatar!}" width="100" height="100" alt="${user.nickname!}">
<h3>${blog_title!}</h3>
<h4>
<a href="${blog_url!}" target="_blank">${blog_url!}</a>
</h4>
</div>
---
<@postTag method="archiveYear">
<#list archives as archive>
## ${archive.year?c}
<#list archive.posts?sort_by("createTime")?reverse as post>
- <a href="<#if !globalAbsolutePathEnabled!true>${blog_url!}</#if>${post.fullPath!}" title="${post.title!}" target="_blank">${post.title!}</a>
</#list>
</#list>
</@postTag>
## 分类目录
<@categoryTag method="list">
<#list categories as category>
- <a href="<#if !globalAbsolutePathEnabled!true>${blog_url!}</#if>${category.fullPath!}" target="_blank">${category.name!}</a>
</#list>
</@categoryTag>
## 标签
<@tagTag method="list">
<#list tags as tag>
- <a href="<#if !globalAbsolutePathEnabled!true>${blog_url!}</#if>${tag.fullPath!}" target="_blank">${tag.name!}</a>
</#list>
</@tagTag>