mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
7c6a841b07
commit
72964cbbdf
|
@ -6,6 +6,7 @@ import cc.ryanc.halo.model.dto.HaloConst;
|
|||
import cc.ryanc.halo.model.dto.Theme;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.sun.syndication.feed.rss.Channel;
|
||||
|
@ -29,10 +30,6 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributeView;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -222,22 +219,6 @@ public class HaloUtils {
|
|||
return tpls;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间
|
||||
*
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String getStringDate(String format) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(format);
|
||||
String dateString = formatter.format(new Date());
|
||||
return dateString;
|
||||
}
|
||||
|
||||
public static String getStringDate(Date date, String format) {
|
||||
Long unixTime = Long.parseLong(String.valueOf(date.getTime() / 1000));
|
||||
return Instant.ofEpochSecond(unixTime).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(format));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出为文件
|
||||
*
|
||||
|
@ -331,7 +312,7 @@ public class HaloUtils {
|
|||
String urlItem;
|
||||
String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
|
||||
for (Post post : posts) {
|
||||
urlItem = "<url><loc>" + urlPath + post.getPostUrl() + "</loc><lastmod>" + getStringDate(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + "</lastmod>" + "</url>";
|
||||
urlItem = "<url><loc>" + urlPath + post.getPostUrl() + "</loc><lastmod>" + DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + "</lastmod>" + "</url>";
|
||||
urlBody += urlItem;
|
||||
}
|
||||
return head + urlBody + "</urlset>";
|
||||
|
|
|
@ -114,7 +114,7 @@ public class BackupController {
|
|||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/databases/");
|
||||
}
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
|
||||
String distName = "databases_backup_" + HaloUtils.getStringDate("yyyyMMddHHmmss");
|
||||
String distName = "databases_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
//压缩文件
|
||||
ZipUtil.zip(srcPath + "halo.mv.db", System.getProperties().getProperty("user.home") + "/halo/backup/databases/" + distName + ".zip");
|
||||
log.info("当前时间:{},执行了数据库备份。", DateUtil.now());
|
||||
|
@ -137,7 +137,7 @@ public class BackupController {
|
|||
}
|
||||
File path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
String srcPath = path.getAbsolutePath();
|
||||
String distName = "resources_backup_" + HaloUtils.getStringDate("yyyyMMddHHmmss");
|
||||
String distName = "resources_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
//执行打包
|
||||
ZipUtil.zip(srcPath, System.getProperties().getProperty("user.home") + "/halo/backup/resources/" + distName + ".zip");
|
||||
log.info("当前时间:{},执行了资源文件备份。", DateUtil.now());
|
||||
|
@ -161,7 +161,7 @@ public class BackupController {
|
|||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");
|
||||
}
|
||||
//打包好的文件名
|
||||
String distName = "posts_backup_" + HaloUtils.getStringDate("yyyyMMddHHmmss");
|
||||
String distName = "posts_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/posts/" + distName;
|
||||
for (Post post : posts) {
|
||||
HaloUtils.postToFile(post.getPostContentMd(), srcPath, post.getPostTitle() + ".md");
|
||||
|
|
|
@ -7,7 +7,6 @@ import cc.ryanc.halo.model.enums.AllowCommentEnum;
|
|||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.TrueFalseEnum;
|
||||
import cc.ryanc.halo.service.*;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
@ -169,7 +168,7 @@ public class InstallController {
|
|||
optionsService.saveOption(BlogPropertiesEnum.THEME.getProp(), "anatole");
|
||||
|
||||
//建立网站时间
|
||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_START.getProp(), HaloUtils.getStringDate("yyyy-MM-dd"));
|
||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_START.getProp(), DateUtil.format(DateUtil.date(),"yyyy-MM-dd"));
|
||||
|
||||
//默认不配置邮件系统
|
||||
optionsService.saveOption(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp(), TrueFalseEnum.FALSE.getDesc());
|
||||
|
|
Loading…
Reference in New Issue