1、增加配置html

This commit is contained in:
guwd 2020-12-02 10:29:43 +08:00
parent 075caec9ef
commit ae904c1584
4 changed files with 45 additions and 34 deletions

View File

@ -100,6 +100,9 @@ public class GeneraterAction extends BaseAction {
@Value("${ms.manager.path}") @Value("${ms.manager.path}")
private String managerPath; private String managerPath;
@Value("${ms.diy.html-dir:html}")
private String htmlDir;
/** /**
* /** * /**
* 更新主页 * 更新主页
@ -131,7 +134,7 @@ public class GeneraterAction extends BaseAction {
if (!FileUtil.exist(ParserUtil.buildTempletPath())) { if (!FileUtil.exist(ParserUtil.buildTempletPath())) {
return ResultData.build().error(getResString("templet.file")); return ResultData.build().error(getResString("templet.file"));
} else { } else {
CmsParserUtil.generate(tmpFileName, generateFileName); CmsParserUtil.generate(tmpFileName, generateFileName,htmlDir);
return ResultData.build().success(); return ResultData.build().success();
} }
} }
@ -185,7 +188,7 @@ public class GeneraterAction extends BaseAction {
continue; continue;
} }
CmsParserUtil.generateList(column, articleIdList.size()); CmsParserUtil.generateList(column, articleIdList.size(),htmlDir);
break; break;
case "2":// 单页 case "2":// 单页
if (articleIdList.size() == 0) { if (articleIdList.size() == 0) {
@ -195,7 +198,7 @@ public class GeneraterAction extends BaseAction {
BeanUtil.copyProperties(column, columnArticleIdBean, copyOptions); BeanUtil.copyProperties(column, columnArticleIdBean, copyOptions);
articleIdList.add(columnArticleIdBean); articleIdList.add(columnArticleIdBean);
} }
CmsParserUtil.generateBasic(articleIdList); CmsParserUtil.generateBasic(articleIdList,htmlDir);
break; break;
} }
} }
@ -226,7 +229,7 @@ public class GeneraterAction extends BaseAction {
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
PageBean page = new PageBean(); PageBean page = new PageBean();
map.put(ParserUtil.HTML, ParserUtil.HTML); map.put(ParserUtil.HTML, htmlDir);
map.put(ParserUtil.URL, BasicUtil.getUrl()); map.put(ParserUtil.URL, BasicUtil.getUrl());
map.put(ParserUtil.PAGE, page); map.put(ParserUtil.PAGE, page);
// 生成所有栏目的文章 // 生成所有栏目的文章
@ -258,7 +261,7 @@ public class GeneraterAction extends BaseAction {
} }
// 有符合条件的就更新 // 有符合条件的就更新
if (articleIdList.size() > 0) { if (articleIdList.size() > 0) {
CmsParserUtil.generateBasic(articleIdList); CmsParserUtil.generateBasic(articleIdList,htmlDir);
} }
} }
@ -277,7 +280,7 @@ public class GeneraterAction extends BaseAction {
public String viewIndex(HttpServletRequest request, @PathVariable String position, HttpServletResponse response) { public String viewIndex(HttpServletRequest request, @PathVariable String position, HttpServletResponse response) {
AppEntity app = BasicUtil.getApp(); AppEntity app = BasicUtil.getApp();
// 组织主页预览地址 // 组织主页预览地址
String indexPosition = app.getAppHostUrl() + File.separator + ParserUtil.HTML + File.separator + app.getAppDir() String indexPosition = app.getAppHostUrl() + File.separator + htmlDir+ File.separator + app.getAppDir()
+ File.separator + position + ParserUtil.HTML_SUFFIX; + File.separator + position + ParserUtil.HTML_SUFFIX;
return "redirect:" + indexPosition; return "redirect:" + indexPosition;
} }

View File

@ -46,6 +46,7 @@ import net.mingsoft.mdiy.entity.ModelEntity;
import net.mingsoft.mdiy.util.ParserUtil; import net.mingsoft.mdiy.util.ParserUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -102,6 +103,10 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
private IModelBiz modelBiz; private IModelBiz modelBiz;
@Value("${ms.diy.html-dir:html}")
private String htmlDir;
/** /**
* 动态列表页 * 动态列表页
*/ */
@ -121,7 +126,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
String content = ""; String content = "";
try { try {
//根据模板路径参数生成 //根据模板路径参数生成
content = CmsParserUtil.generate(ParserUtil.INDEX + ParserUtil.HTM_SUFFIX, map); content = CmsParserUtil.generate(ParserUtil.INDEX + ParserUtil.HTM_SUFFIX, map,htmlDir);
} catch (TemplateNotFoundException e) { } catch (TemplateNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MalformedTemplateNameException e) { } catch (MalformedTemplateNameException e) {
@ -179,7 +184,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
String content = ""; String content = "";
try { try {
//根据模板路径参数生成 //根据模板路径参数生成
content = CmsParserUtil.generate(columnArticles.get(0).getCategoryListUrl(), map); content = CmsParserUtil.generate(columnArticles.get(0).getCategoryListUrl(),map,htmlDir);
} catch (TemplateNotFoundException e) { } catch (TemplateNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MalformedTemplateNameException e) { } catch (MalformedTemplateNameException e) {
@ -281,7 +286,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
} }
try { try {
//根据模板路径参数生成 //根据模板路径参数生成
content = CmsParserUtil.generate(column.getCategoryUrl(), map); content = CmsParserUtil.generate(column.getCategoryUrl(), map,htmlDir);
} catch (TemplateNotFoundException e) { } catch (TemplateNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MalformedTemplateNameException e) { } catch (MalformedTemplateNameException e) {
@ -332,7 +337,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
int typeId = 0; int typeId = 0;
String categoryIds = BasicUtil.getString("categoryId"); String categoryIds = BasicUtil.getString("categoryId");
//当传递了栏目编号但不是栏目集合 //当传递了栏目编号但不是栏目集合
if (!StringUtil.isBlank(categoryIds) && !categoryIds.contains(",")) { if (StringUtils.isNotBlank(categoryIds) && !categoryIds.contains(",")) {
typeId = Integer.parseInt(categoryIds); typeId = Integer.parseInt(categoryIds);
} }
@ -385,7 +390,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
} }
// 保存至自定义字段集合 // 保存至自定义字段集合
if (!StringUtil.isBlank(value)) { if (StringUtils.isNotBlank(value)) {
diyFieldName.put(entry.getKey(), value); diyFieldName.put(entry.getKey(), value);
//判断请求中的是否是自定义模型中的字段 //判断请求中的是否是自定义模型中的字段
if (filedStr.contains(entry.getKey())) { if (filedStr.contains(entry.getKey())) {
@ -430,7 +435,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
params.put(ParserUtil.PAGE, page); params.put(ParserUtil.PAGE, page);
params.put(ParserUtil.HTML, ParserUtil.HTML); params.put(ParserUtil.HTML, htmlDir);
//动态解析 //动态解析
params.put(ParserUtil.IS_DO, false); params.put(ParserUtil.IS_DO, false);
//设置动态请求的模块路径 //设置动态请求的模块路径
@ -473,7 +478,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); params.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
params.put(ParserUtil.PAGE, page); params.put(ParserUtil.PAGE, page);
params.put(ParserUtil.HTML, ParserUtil.HTML); params.put(ParserUtil.HTML, htmlDir);
//动态解析 //动态解析
params.put(ParserUtil.IS_DO, false); params.put(ParserUtil.IS_DO, false);
//设置动态请求的模块路径 //设置动态请求的模块路径
@ -483,7 +488,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
String content = ""; String content = "";
try { try {
//根据模板路径参数生成 //根据模板路径参数生成
content = CmsParserUtil.generate(SEARCH + ParserUtil.HTM_SUFFIX, params); content = CmsParserUtil.generate(SEARCH + ParserUtil.HTM_SUFFIX, params,htmlDir);
} catch (TemplateNotFoundException e) { } catch (TemplateNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MalformedTemplateNameException e) { } catch (MalformedTemplateNameException e) {

View File

@ -41,6 +41,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import net.mingsoft.base.biz.impl.BaseBizImpl; import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao; import net.mingsoft.base.dao.IBaseDao;
@ -73,6 +74,9 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
@Autowired @Autowired
private ICategoryDao categoryDao; private ICategoryDao categoryDao;
@Value("${ms.diy.html-dir:html}")
private String htmlDir;
@Override @Override
protected IBaseDao getDao() { protected IBaseDao getDao() {
@ -128,7 +132,7 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
PageBean page = new PageBean(); PageBean page = new PageBean();
map.put(ParserUtil.HTML, ParserUtil.HTML); map.put(ParserUtil.HTML, htmlDir);
map.put(ParserUtil.URL, BasicUtil.getUrl()); map.put(ParserUtil.URL, BasicUtil.getUrl());
map.put(ParserUtil.PAGE, page); map.put(ParserUtil.PAGE, page);
@ -148,7 +152,7 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
articleIdList = queryIdsByCategoryIdForParser(contentBean); articleIdList = queryIdsByCategoryIdForParser(contentBean);
// 有符合条件的就更新 // 有符合条件的就更新
if (articleIdList.size() > 0) { if (articleIdList.size() > 0) {
CmsParserUtil.generateBasic(articleIdList); CmsParserUtil.generateBasic(articleIdList,htmlDir);
} }
} }
} }
@ -180,7 +184,7 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
PageBean page = new PageBean(); PageBean page = new PageBean();
map.put(ParserUtil.HTML, ParserUtil.HTML); map.put(ParserUtil.HTML, htmlDir);
map.put(ParserUtil.URL, BasicUtil.getUrl()); map.put(ParserUtil.URL, BasicUtil.getUrl());
map.put(ParserUtil.PAGE, page); map.put(ParserUtil.PAGE, page);
@ -190,7 +194,7 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
switch (column.getCategoryType()) { switch (column.getCategoryType()) {
//TODO 暂时先用字符串代替 //TODO 暂时先用字符串代替
case "1": // 列表 case "1": // 列表
CmsParserUtil.generateList(column, articleIdList.size()); CmsParserUtil.generateList(column, articleIdList.size(),htmlDir);
break; break;
case "2":// 单页 case "2":// 单页
if(articleIdList.size()==0){ if(articleIdList.size()==0){
@ -200,7 +204,7 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
BeanUtil.copyProperties(column,columnArticleIdBean,copyOptions); BeanUtil.copyProperties(column,columnArticleIdBean,copyOptions);
articleIdList.add(columnArticleIdBean); articleIdList.add(columnArticleIdBean);
} }
CmsParserUtil.generateBasic(articleIdList); CmsParserUtil.generateBasic(articleIdList,htmlDir);
break; break;
} }
} }
@ -224,13 +228,13 @@ public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> imp
map.put(ParserUtil.URL, BasicUtil.getUrl()); map.put(ParserUtil.URL, BasicUtil.getUrl());
} }
//设置生成的路径 //设置生成的路径
map.put(ParserUtil.HTML, ParserUtil.HTML); map.put(ParserUtil.HTML, htmlDir);
//设置站点编号 //设置站点编号
if(BasicUtil.getWebsiteApp() !=null){ if(BasicUtil.getWebsiteApp() !=null){
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
String read = ParserUtil.rendering(templatePath, map); String read = ParserUtil.rendering(templatePath, map);
FileUtil.writeString(read, ParserUtil.buildHtmlPath(targetPath), net.mingsoft.base.constant.Const.UTF8); FileUtil.writeString(read, ParserUtil.buildHtmlPath(targetPath,htmlDir), net.mingsoft.base.constant.Const.UTF8);
} }
} }

View File

@ -31,7 +31,6 @@ import java.util.concurrent.ExecutorService;
* 文章解析工具类 * 文章解析工具类
*/ */
public class CmsParserUtil extends ParserUtil { public class CmsParserUtil extends ParserUtil {
/** /**
* 封面 * 封面
*/ */
@ -48,14 +47,14 @@ public class CmsParserUtil extends ParserUtil {
* 生成后的路径默认生成的html文件所以不能带.html后缀 * 生成后的路径默认生成的html文件所以不能带.html后缀
* @throws IOException * @throws IOException
*/ */
public static void generate(String templatePath, String targetPath) throws IOException { public static void generate(String templatePath, String targetPath,String htmlDir) throws IOException {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put(IS_DO, false); map.put(IS_DO, false);
CategoryEntity column = new CategoryEntity(); CategoryEntity column = new CategoryEntity();
//内容管理栏目编码 //内容管理栏目编码
map.put(COLUMN, column); map.put(COLUMN, column);
String content = CmsParserUtil.generate(templatePath, map); String content = CmsParserUtil.generate(templatePath, map,htmlDir);
FileUtil.writeString(content, ParserUtil.buildHtmlPath(targetPath), Const.UTF8); FileUtil.writeString(content, ParserUtil.buildHtmlPath(targetPath,htmlDir), Const.UTF8);
} }
/** /**
@ -67,7 +66,7 @@ public class CmsParserUtil extends ParserUtil {
* @throws ParseException * @throws ParseException
* @throws IOException * @throws IOException
*/ */
public static void generateList(CategoryEntity column, int articleIdTotal) public static void generateList(CategoryEntity column, int articleIdTotal,String htmlDir)
throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException {
try{ try{
// 文章的栏目模型编号 // 文章的栏目模型编号
@ -86,7 +85,7 @@ public class CmsParserUtil extends ParserUtil {
map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir()); map.put(ParserUtil.APP_DIR, BasicUtil.getWebsiteApp().getAppDir());
} }
map.put(ParserUtil.HTML, ParserUtil.HTML); map.put(ParserUtil.HTML, htmlDir);
map.put(ParserUtil.URL, BasicUtil.getUrl()); map.put(ParserUtil.URL, BasicUtil.getUrl());
map.put(ParserUtil.PAGE, page); map.put(ParserUtil.PAGE, page);
@ -122,7 +121,7 @@ public class CmsParserUtil extends ParserUtil {
//文章列表页没有写文章列表标签总数为0 //文章列表页没有写文章列表标签总数为0
if (totalPageSize <= 0) { if (totalPageSize <= 0) {
// 数据库中第一页是从开始0*size // 数据库中第一页是从开始0*size
columnListPath = ParserUtil.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX); columnListPath = ParserUtil.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX,htmlDir);
// 设置分页的起始位置 // 设置分页的起始位置
page.setPageNo(pageNo); page.setPageNo(pageNo);
String read = ParserUtil.rendering(File.separator + column.getCategoryListUrl(), parserParams); String read = ParserUtil.rendering(File.separator + column.getCategoryListUrl(), parserParams);
@ -135,11 +134,11 @@ public class CmsParserUtil extends ParserUtil {
// 数据库中第一页是从开始0*size // 数据库中第一页是从开始0*size
// 首页路径index.html // 首页路径index.html
columnListPath = ParserUtil columnListPath = ParserUtil
.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX); .buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.INDEX,htmlDir);
} else { } else {
// 其他路径list-2.html // 其他路径list-2.html
columnListPath = ParserUtil columnListPath = ParserUtil
.buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.PAGE_LIST + pageNo); .buildHtmlPath(column.getCategoryPath() + File.separator + ParserUtil.PAGE_LIST + pageNo,htmlDir);
} }
// 设置分页的起始位置 // 设置分页的起始位置
page.setPageNo(pageNo); page.setPageNo(pageNo);
@ -164,7 +163,7 @@ public class CmsParserUtil extends ParserUtil {
* @throws MalformedTemplateNameException * @throws MalformedTemplateNameException
* @throws TemplateNotFoundException * @throws TemplateNotFoundException
*/ */
public static void generateBasic(List<CategoryBean> articleIdList) { public static void generateBasic(List<CategoryBean> articleIdList,String htmlDir) {
Map<Object, Object> contentModelMap = new HashMap<Object, Object>(); Map<Object, Object> contentModelMap = new HashMap<Object, Object>();
ModelEntity contentModel = null; ModelEntity contentModel = null;
@ -211,10 +210,10 @@ public class CmsParserUtil extends ParserUtil {
generateIds.add(articleId); generateIds.add(articleId);
//如果是封面就生成index.html //如果是封面就生成index.html
if(Integer.parseInt(articleIdList.get(artId).getCategoryType()) == COLUMN_TYPE_COVER) { if(Integer.parseInt(articleIdList.get(artId).getCategoryType()) == COLUMN_TYPE_COVER) {
writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX); writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX,htmlDir);
} else { } else {
// 组合文章路径如:html/站点id/栏目id/文章id.html // 组合文章路径如:html/站点id/栏目id/文章id.html
writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId); writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId,htmlDir);
} }
Map<String, Object> parserParams = new HashMap<String, Object>(); Map<String, Object> parserParams = new HashMap<String, Object>();
@ -262,7 +261,7 @@ public class CmsParserUtil extends ParserUtil {
String content = null; String content = null;
try { try {
SpringUtil.setRequest(request); SpringUtil.setRequest(request);
content = CmsParserUtil.generate(columnUrl, cloneMap); content = CmsParserUtil.generate(columnUrl, cloneMap,htmlDir);
FileUtil.writeString(content, finalWritePath, Const.UTF8); FileUtil.writeString(content, finalWritePath, Const.UTF8);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();