Skip to content

Commit

Permalink
pref: remove cdn_domain option.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Dec 27, 2019
1 parent 04512db commit b9e64cb
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import run.halo.app.cache.StringCacheStore;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.exception.ForbiddenException;
import run.halo.app.exception.NotFoundException;
import run.halo.app.model.entity.Category;
import run.halo.app.model.entity.Post;
import run.halo.app.model.entity.PostMeta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import run.halo.app.event.theme.ThemeActivatedEvent;
import run.halo.app.event.user.UserUpdatedEvent;
import run.halo.app.handler.theme.config.support.ThemeProperty;
import run.halo.app.model.properties.OtherProperties;
import run.halo.app.model.support.HaloConst;
import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService;
Expand Down Expand Up @@ -99,8 +98,7 @@ private void loadOptionsConfig() throws TemplateModelException {
private void loadThemeConfig() throws TemplateModelException {
ThemeProperty activatedTheme = themeService.getActivatedTheme();
configuration.setSharedVariable("theme", activatedTheme);
String baseUrl = optionService.getByPropertyOrDefault(OtherProperties.CDN_DOMAIN, String.class, optionService.getBlogBaseUrl());
configuration.setSharedVariable("static", baseUrl + "/" + activatedTheme.getFolderName());
configuration.setSharedVariable("static", optionService.getBlogBaseUrl() + "/" + activatedTheme.getFolderName());
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
log.debug("Loaded theme and settings");
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/run/halo/app/model/properties/OtherProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
*
* @author johnniang
* @author ryanwang
* @date 4/1/19
* @date 2019-04-01
*/
public enum OtherProperties implements PropertyEnum {

CDN_DOMAIN("blog_cdn_domain", String.class, ""),

/**
* Global custom head.
*/
CUSTOM_HEAD("blog_custom_head", String.class, ""),

/**
* Content page(post,sheet) custom head.
*/
CUSTOM_CONTENT_HEAD("blog_custom_content_head", String.class, ""),

/**
* Statistics platform code,such as Google Analytics.
*/
STATISTICS_CODE("blog_statistics_code", String.class, "");

private final String value;
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/run/halo/app/service/impl/PostServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -28,7 +26,6 @@
import run.halo.app.model.enums.LogType;
import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.params.PostQuery;
import run.halo.app.model.properties.OtherProperties;
import run.halo.app.model.vo.ArchiveMonthVO;
import run.halo.app.model.vo.ArchiveYearVO;
import run.halo.app.model.vo.PostDetailVO;
Expand Down Expand Up @@ -454,9 +451,6 @@ public Page<PostListVO> convertToListVo(Page<Post> postPage) {
// Get post meta list map
Map<Integer, List<PostMeta>> postMetaListMap = postMetaService.listPostMetaAsMap(postIds);

// Get cdn domain
String cdnDomain = optionService.getByPropertyOrDefault(OtherProperties.CDN_DOMAIN, String.class, StringUtils.EMPTY);

String blogUrl = optionService.getBlogBaseUrl();

return postPage.map(post -> {
Expand Down Expand Up @@ -495,10 +489,6 @@ public Page<PostListVO> convertToListVo(Page<Post> postPage) {
// Set comment count
postListVO.setCommentCount(commentCountMap.getOrDefault(post.getId(), 0L));

if (StringUtils.isNotEmpty(cdnDomain) && StringUtils.isNotEmpty(postListVO.getThumbnail())) {
postListVO.setThumbnail(postListVO.getThumbnail().replace(blogUrl, cdnDomain));
}

return postListVO;
});
}
Expand Down Expand Up @@ -559,21 +549,6 @@ private PostDetailVO convertTo(@NonNull Post post, @Nullable List<Tag> tags, @Nu
postDetailVO.setPostMetaIds(postMetaIds);
postDetailVO.setPostMetas(postMetaService.convertTo(postMetaList));

// Get cdn domain
String cdnDomain = optionService.getByPropertyOrDefault(OtherProperties.CDN_DOMAIN, String.class, StringUtils.EMPTY);
String blogUrl = optionService.getBlogBaseUrl();

if (StringUtils.isNotEmpty(cdnDomain) && StringUtils.isNotEmpty(postDetailVO.getThumbnail())) {
postDetailVO.setThumbnail(postDetailVO.getThumbnail().replace(blogUrl, cdnDomain));
}

Document document = Jsoup.parse(postDetailVO.getFormatContent());
document.select("img").forEach(img -> {
String src = img.attr("src");
img.attr("src", src.replace(blogUrl, cdnDomain));
});

postDetailVO.setFormatContent(document.html());
return postDetailVO;
}

Expand Down
29 changes: 15 additions & 14 deletions src/main/resources/templates/common/macro/global_macro.ftl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<#ftl strip_whitespace=true>

<#-- 统计代码 -->
<#-- statistics_code -->
<#macro statistics>
${options.blog_statistics_code!}
</#macro>

<#-- 页脚信息 -->
<#-- footer info -->
<#macro footer_info>
${options.blog_footer_info!}
</#macro>
Expand All @@ -14,19 +14,20 @@
${options.blog_custom_head!}
</#macro>

<#-- Favicon -->
<#macro custom_content_head>
<#if is_post?? || is_sheet??>
${options.blog_custom_content_head!}
</#if>
</#macro>

<#-- favicon -->
<#macro favicon>
<#if options.blog_favicon?? && options.blog_favicon!=''>
<link rel="shortcut icon" type="images/x-icon" href="${options.blog_favicon!}">
</#if>
</#macro>

<#-- 站点验证代码,已废弃 -->
<#macro verification>

</#macro>

<#-- 时间格式化 几...前 -->
<#-- time ago -->
<#macro timeline datetime=.now>
<#assign ct = (.now?long-datetime?long)/1000>
<#if ct gte 31104000>${(ct/31104000)?int} 年前
Expand All @@ -46,9 +47,9 @@
<meta name="robots" content="none">
</#if>
<meta name="generator" content="Halo ${version!}"/>
<@custom_head />
<@verification />
<@favicon />
<@custom_head />
<@custom_content_head />
</#macro>

<#-- global footer -->
Expand All @@ -57,11 +58,11 @@
<@statistics />
</#macro>

<#-- post comment module -->
<#macro comment post,type>
<#-- comment module -->
<#macro comment target,type>
<#if !post.disallowComment!false>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="${options.comment_internal_plugin_js!'//cdn.jsdelivr.net/gh/halo-dev/halo-comment@latest/dist/halo-comment.min.js'}"></script>
<halo-comment id="${post.id}" type="${type}"/>
<halo-comment id="${target.id}" type="${type}"/>
</#if>
</#macro>
2 changes: 1 addition & 1 deletion src/main/resources/templates/themes/anatole/archives.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#include "module/macro.ftl">
<@head title="归档 · ${options.blog_title!'Anatole'}" keywords="文章归档,${options.seo_keywords!'Anatole'}" description="${options.seo_description!'Anatole'}"></@head>
<@head title="归档 · ${options.blog_title!}" keywords="${options.seo_keywords!}" description="${options.seo_description!}" />
<#include "module/sidebar.ftl">
<div class="main">
<#include "module/page-top.ftl">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/themes/anatole/category.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#include "module/macro.ftl">
<@head title="分类:${category.name} · ${options.blog_title!'Anatole'}" keywords="${options.seo_keywords!'Anatole'}" description="${options.seo_description!'Anatole'}"></@head>
<@head title="分类:${category.name} · ${options.blog_title!}" keywords="${options.seo_keywords!}" description="${options.seo_description!}" />
<#include "module/sidebar.ftl">
<div class="main">
<#include "module/page-top.ftl">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/themes/anatole/index.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#include "module/macro.ftl">
<@head title="${options.blog_title!'Anatole'}" keywords="${options.seo_keywords!'Anatole'}" description="${options.seo_description!'Anatole'}"></@head>
<@head title="${options.blog_title!}" keywords="${options.seo_keywords!}" description="${options.seo_description!}" />
<#include "module/sidebar.ftl">
<div class="main">
<#include "module/page-top.ftl">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/themes/anatole/links.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#include "module/macro.ftl">
<@head title="友情链接 · ${options.blog_title!'Anatole'}" keywords="${options.seo_keywords!'Anatole'}" description="${options.seo_description!'Anatole'}"></@head>
<@head title="友情链接 · ${options.blog_title!}" keywords="${options.seo_keywords!}" description="${options.seo_description!}" />
<#include "module/sidebar.ftl">
<div class="main">
<#include "module/page-top.ftl">
Expand Down
38 changes: 35 additions & 3 deletions src/main/resources/templates/themes/anatole/module/macro.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<#import "/common/macro/common_macro.ftl" as common>
<#macro head title,keywords,description>
<!DOCTYPE html>
<html>
Expand All @@ -14,10 +13,43 @@
<meta name="author" content="${user.nickname!}" />
<meta name="keywords" content="${keywords!}"/>
<meta name="description" content="${description!}" />
<@common.globalHeader />
<@global.head />
<link href="${static!}/source/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
<link rel="stylesheet" href="${static!}/source/css/blog_basic.min.css?version=88107691fe">
<link href="${static!}/source/css/style.min.css" type="text/css" rel="stylesheet" />

<#if is_post?? || is_sheet??>
<link href="${static!}/source/plugins/prism/css/prism-${settings.code_pretty!'Default'}.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${static!}/source/plugins/prism/js/prism.js"></script>
<style>
table {
border-spacing: 0;
border-collapse: collapse;
margin-top: 0;
margin-bottom: 16px;
display: block;
width: 100%;
overflow: auto;
}
table th {
font-weight: 600;
}
table th,
table td {
padding: 6px 13px;
border: 1px solid #dfe2e5;
}
table tr {
background-color: #fff;
border-top: 1px solid #c6cbd1;
}
table tr:nth-child(2n) {
background-color: #f6f8fa;
}
</style>
</#if>

<link rel="alternate" type="application/rss+xml" title="atom 1.0" href="/atom.xml">
<style>
<#if !settings.post_title_uppper!true>
Expand Down Expand Up @@ -76,7 +108,7 @@
xhr.send();
</#if>
</script>
<@common.statistics />
<@global.statistics />
</body>
</html>
</#macro>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<div class="title">
<img src="${options.blog_logo!'${static!}/source/images/[email protected]'}" style="width:127px;<#if settings.avatar_circle!false>border-radius:50%</#if>" />
<h3 title="">
<a href="${context!}">${options.blog_title!'Anatole'}</a>
<a href="${context!}">${options.blog_title!}</a>
</h3>
<div class="description">
<#if settings.hitokoto!false>
<p id="yiyan">获取中...</p>
<#else >
<p>${user.description!'A other Halo theme'}</p>
<p>${user.description!}</p>
</#if>
</div>
</div>
Expand All @@ -24,7 +24,7 @@
<a href="https://github.com/halo-dev/halo" target="_blank">Proudly published with Halo&#65281;</a>
</div>
<div class="footer_text">
<@common.footer_info />
<@global.footer_info />
</div>
</a>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/templates/themes/anatole/photos.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<#include "/common/macro/common_macro.ftl">
<!DOCTYPE HTML>
<html>
<head>
Expand Down Expand Up @@ -44,6 +43,6 @@
<script src="${static!}/source/plugins/gallery/js/jquery.min.js"></script>
<script src="${static!}/source/plugins/gallery/js/skel.min.js"></script>
<script src="${static!}/source/plugins/gallery/js/main.js"></script>
<@statistics></@statistics>
<@global.statistics />
</body>
</html>
31 changes: 1 addition & 30 deletions src/main/resources/templates/themes/anatole/post.ftl
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
<#include "module/macro.ftl">
<@head title="${post.title!} · ${options.blog_title!'Anatole'}" keywords="${post.title!},${options.seo_keywords!'Anatole'},${tagWords!}" description="${post.summary!'Anatole'}"></@head>
<@head title="${post.title!} · ${options.blog_title!}" keywords="${post.title!},${options.seo_keywords!},${tagWords!}" description="${post.summary!}" />
<#include "module/sidebar.ftl">
<div class="main">
<link href="${static!}/source/plugins/prism/css/prism-${settings.code_pretty!'Default'}.css" type="text/css" rel="stylesheet" />
<style>
table {
border-spacing: 0;
border-collapse: collapse;
margin-top: 0;
margin-bottom: 16px;
display: block;
width: 100%;
overflow: auto;
}
table th {
font-weight: 600;
}
table th,
table td {
padding: 6px 13px;
border: 1px solid #dfe2e5;
}
table tr {
background-color: #fff;
border-top: 1px solid #c6cbd1;
}
table tr:nth-child(2n) {
background-color: #f6f8fa;
}
</style>
<#include "module/page-top.ftl">
<div class="autopagerize_page_element">
<div class="content">
Expand Down Expand Up @@ -96,5 +68,4 @@
</div>
</div>
</div>
<script type="text/javascript" src="${static!}/source/plugins/prism/js/prism.js"></script>
<@footer></@footer>
Loading

0 comments on commit b9e64cb

Please sign in to comment.