mirror of https://github.com/halo-dev/halo
🍎 新增百度主动推送
parent
a4219d34f4
commit
f8597a3406
52
PREVIEW.md
52
PREVIEW.md
|
@ -1,49 +1,61 @@
|
||||||
# Halo界面预览
|
# Halo界面预览
|
||||||
|
|
||||||
## 安装界面
|
## 安装页
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 后台登录界面
|
## 后台登录
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 后台首页
|
## 后台首页
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 文章管理
|

|
||||||
|
|
||||||

|
## 文章列表
|
||||||
|
|
||||||
## 文章编写
|

|
||||||
|
|
||||||

|
## 文章编辑
|
||||||
|
|
||||||
## 附件管理
|

|
||||||
|
|
||||||

|
## 标签列表
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 预设页面
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 附件页面
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## 评论管理
|
## 评论管理
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 评论系统
|
## 菜单管理
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## 系统设置
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## 主题管理
|
## 主题管理
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 默认主题
|

|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Material主题(感谢[Viosey](https://viosey.com))
|
## Material主题(感谢[Viosey](https://viosey.com))
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Anatole主题(感谢[Caicai](https://www.caicai.me/))
|
## Anatole主题(感谢[Caicai](https://www.caicai.me/))
|
||||||
|
|
||||||

|

|
23
README.md
23
README.md
|
@ -10,13 +10,14 @@
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
|
|
||||||
- [Introduction 简介](#Introduction-简介)
|
- [Introduction 简介](#introduction-简介)
|
||||||
- [Quickstart 快速开始](#Quickstart-快速开始)
|
- [Quickstart 快速开始](#quickstart-快速开始)
|
||||||
- [Demo 演示](#Demo-演示)
|
- [Demo 演示](#demo-演示)
|
||||||
- [Download 下载](#Download-下载)
|
- [Download 下载](#download-下载)
|
||||||
- [Docs 文档](#Docs-文档)
|
- [Docs 文档](#docs-文档)
|
||||||
- [License 许可证](#License-许可证)
|
- [License 许可证](#license-许可证)
|
||||||
- [Thanks 感谢](#Thanks-感谢)
|
- [Todo 后续功能](#todo-后续功能)
|
||||||
|
- [Thanks 感谢](#thanks-感谢)
|
||||||
|
|
||||||
## Introduction 简介
|
## Introduction 简介
|
||||||
|
|
||||||
|
@ -47,6 +48,8 @@ Let's start: http://localhost:8090
|
||||||
|
|
||||||
[SNAIL BLOG](https://slogc.cc)
|
[SNAIL BLOG](https://slogc.cc)
|
||||||
|
|
||||||
|
[宋浩志博客](http://songhaozhi.com/)
|
||||||
|
|
||||||
## Download 下载
|
## Download 下载
|
||||||
|
|
||||||
[Download](https://github.com/ruibaby/halo/releases)
|
[Download](https://github.com/ruibaby/halo/releases)
|
||||||
|
@ -61,6 +64,12 @@ Let's start: http://localhost:8090
|
||||||
|
|
||||||
[](https://github.com/ruibaby/halo/blob/master/LICENSE)
|
[](https://github.com/ruibaby/halo/blob/master/LICENSE)
|
||||||
|
|
||||||
|
## Todo 后续功能
|
||||||
|
|
||||||
|
- [ ] 文章阅读统计
|
||||||
|
- [ ] 文章顶置
|
||||||
|
- [ ] 集成又拍云,七牛云等云服务
|
||||||
|
|
||||||
## Thanks 感谢
|
## Thanks 感谢
|
||||||
|
|
||||||
Halo的诞生离不开下面这些项目:
|
Halo的诞生离不开下面这些项目:
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.sun.syndication.io.WireFeedOutput;
|
||||||
import io.github.biezhi.ome.OhMyEmail;
|
import io.github.biezhi.ome.OhMyEmail;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.ImageReadParam;
|
import javax.imageio.ImageReadParam;
|
||||||
|
@ -644,4 +645,58 @@ public class HaloUtil {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百度实时推送
|
||||||
|
*
|
||||||
|
* @param blogUrl 博客地址
|
||||||
|
* @param token 百度推送token
|
||||||
|
* @param urls 文章路径
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static String baiduPost(String blogUrl,String token,String urls){
|
||||||
|
String url = "http://data.zz.baidu.com/urls?site="+blogUrl+"&token="+token;
|
||||||
|
String result="";
|
||||||
|
PrintWriter out=null;
|
||||||
|
BufferedReader in=null;
|
||||||
|
try {
|
||||||
|
//建立URL之间的连接
|
||||||
|
URLConnection conn=new URL(url).openConnection();
|
||||||
|
//设置通用的请求属性
|
||||||
|
conn.setRequestProperty("Host","data.zz.baidu.com");
|
||||||
|
conn.setRequestProperty("User-Agent", "curl/7.12.1");
|
||||||
|
conn.setRequestProperty("Content-Length", "83");
|
||||||
|
conn.setRequestProperty("Content-Type", "text/plain");
|
||||||
|
|
||||||
|
//发送POST请求必须设置如下两行
|
||||||
|
conn.setDoInput(true);
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
|
//获取conn对应的输出流
|
||||||
|
out=new PrintWriter(conn.getOutputStream());
|
||||||
|
out.print(urls.trim());
|
||||||
|
//进行输出流的缓冲
|
||||||
|
out.flush();
|
||||||
|
//通过BufferedReader输入流来读取Url的响应
|
||||||
|
in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
|
String line;
|
||||||
|
while((line=in.readLine())!= null){
|
||||||
|
result += line;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally{
|
||||||
|
try{
|
||||||
|
if(null != out){
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
if(null != in){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}catch(IOException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,7 @@ package cc.ryanc.halo.web.controller.admin;
|
||||||
import cc.ryanc.halo.model.domain.*;
|
import cc.ryanc.halo.model.domain.*;
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
import cc.ryanc.halo.service.CategoryService;
|
import cc.ryanc.halo.service.*;
|
||||||
import cc.ryanc.halo.service.LogsService;
|
|
||||||
import cc.ryanc.halo.service.PostService;
|
|
||||||
import cc.ryanc.halo.service.TagService;
|
|
||||||
import cc.ryanc.halo.util.HaloUtil;
|
import cc.ryanc.halo.util.HaloUtil;
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -24,6 +21,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,6 +47,9 @@ public class PostController extends BaseController{
|
||||||
@Autowired
|
@Autowired
|
||||||
private LogsService logsService;
|
private LogsService logsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OptionsService optionsService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HttpServletRequest request;
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@ -162,7 +163,6 @@ public class PostController extends BaseController{
|
||||||
post.setTags(tags);
|
post.setTags(tags);
|
||||||
}
|
}
|
||||||
postService.saveByPost(post);
|
postService.saveByPost(post);
|
||||||
log.info("已发表新文章:"+post.getPostTitle());
|
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
|
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("未知错误:{0}",e.getMessage());
|
log.error("未知错误:{0}",e.getMessage());
|
||||||
|
@ -271,4 +271,26 @@ public class PostController extends BaseController{
|
||||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
||||||
return null!=post;
|
return null!=post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将所有文章推送到百度
|
||||||
|
* @param baiduToken baiduToken
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/pushAllToBaidu")
|
||||||
|
@ResponseBody
|
||||||
|
public boolean pushAllToBaidu(@PathParam("baiduToken") String baiduToken){
|
||||||
|
if(StringUtils.isEmpty(baiduToken)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String blogUrl = optionsService.findOneOption("blog_url");
|
||||||
|
List<Post> posts = postService.findAllPosts(HaloConst.POST_TYPE_POST);
|
||||||
|
String urls = "";
|
||||||
|
for(Post post:posts){
|
||||||
|
urls+=blogUrl+"/archives/"+post.getPostUrl()+"\n";
|
||||||
|
}
|
||||||
|
String result = HaloUtil.baiduPost(blogUrl,baiduToken,urls);
|
||||||
|
log.info(result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,12 @@
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<input type="text" class="form-control" id="baiduToken" name="seo_baidu_token" value="${options.seo_baidu_token?if_exists}">
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" id="baiduToken" name="seo_baidu_token" value="${options.seo_baidu_token?if_exists}">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-default " id="btn_push_baidu" onclick="pushAllToBaidu()" type="button">推送</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -602,6 +607,22 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function pushAllToBaidu() {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/admin/posts/pushAllToBaidu',
|
||||||
|
data: {
|
||||||
|
baiduToken : $('#baiduToken').val()
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if(data==true){
|
||||||
|
showMsg("推送所有文章成功!","success",1000);
|
||||||
|
}else{
|
||||||
|
showMsg("推送失败!","success",2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
function checkCommentOption() {
|
function checkCommentOption() {
|
||||||
var native = $('input:radio[value=native]:checked').val();
|
var native = $('input:radio[value=native]:checked').val();
|
||||||
var valine = $('input:radio[value=valine]:checked').val();
|
var valine = $('input:radio[value=valine]:checked').val();
|
||||||
|
|
|
@ -104,6 +104,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="anatoleStylePostTitleLower" class="col-sm-4 control-label">文章标题大写:</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="anatole_style_post_title_lower" id="anatoleStylePostTitleLower" value="true" ${((options.anatole_style_post_title_lower?default('true'))=='true')?string('checked','')}> 开启
|
||||||
|
</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="anatole_style_post_title_lower" id="anatoleStylePostTitleLower" value="false" ${((options.anatole_style_post_title_lower?if_exists)=='false')?string('checked','')}> 关闭
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="anatoleStyleHitokoto" class="col-sm-4 control-label">博客描述开启一言:</label>
|
<label for="anatoleStyleHitokoto" class="col-sm-4 control-label">博客描述开启一言:</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
<div class="by_halo">
|
<div class="by_halo">
|
||||||
<a href="https://github.com/ruibaby/halo" target="_blank">Proudly published with Halo!</a>
|
<a href="https://github.com/ruibaby/halo" target="_blank">Proudly published with Halo!</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="footer_text">
|
||||||
|
${options.blog_footer_info?if_exists}
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -17,6 +17,13 @@
|
||||||
<link rel="stylesheet" href="/anatole/source/css/blog_basic.css?version=88107691fe">
|
<link rel="stylesheet" href="/anatole/source/css/blog_basic.css?version=88107691fe">
|
||||||
<link href="/anatole/source/css/style.css" type="text/css" rel="stylesheet" />
|
<link href="/anatole/source/css/style.css" type="text/css" rel="stylesheet" />
|
||||||
<link rel="alternate" type="application/rss+xml" title="atom 1.0" href="/feed.xml">
|
<link rel="alternate" type="application/rss+xml" title="atom 1.0" href="/feed.xml">
|
||||||
|
<#if options.anatole_style_post_title_lower?default("true") == "false">
|
||||||
|
<style>
|
||||||
|
.post .post-title h3 {
|
||||||
|
text-transform: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</#if>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
Loading…
Reference in New Issue