🍎 新增百度主动推送

pull/5/head
RYAN0UP_ 2018-05-02 22:40:00 +08:00
parent a4219d34f4
commit f8597a3406
8 changed files with 173 additions and 33 deletions

View File

@ -1,49 +1,61 @@
# Halo界面预览
## 安装界面
## 安装
![](https://cdn.ryanc.cc/img/github/halo/halo-install.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-install.png)
## 后台登录界面
## 后台登录
![](https://cdn.ryanc.cc/img/github/halo/halo-login.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-login.png)
## 后台首页
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-index.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-index.png)
## 文章管理
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-index-2.png)
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-post.png)
## 文章列表
## 文章编写
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-posts.png)
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-edit.png)
## 文章编辑
## 附件管理
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-edit.png)
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-attach.png)
## 标签列表
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-tags.png)
## 预设页面
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-pages.png)
## 附件页面
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-attach.png)
## 评论管理
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-comment.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-comments.png)
## 评论系统
## 菜单管理
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-comment-system.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-menus.png)
## 系统设置
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-options.png)
## 主题管理
![](https://cdn.ryanc.cc/img/github/halo/halo-admin-theme.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-themes.png)
## 默认主题
![](https://cdn.ryanc.cc/img/github/halo/halo-theme-default.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-admin-themes-options.png)
## Material主题(感谢[Viosey](https://viosey.com))
![](https://cdn.ryanc.cc/img/github/halo/halo-theme-material.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-index-material.png)
## Anatole主题(感谢[Caicai](https://www.caicai.me/))
![](https://cdn.ryanc.cc/img/github/halo/halo-theme-anatole.png)
![](https://cdn.ryanc.cc/img/github/halo-blog/halo-index-anatole.png)

View File

@ -10,13 +10,14 @@
## 目录
- [Introduction 简介](#Introduction-简介)
- [Quickstart 快速开始](#Quickstart-快速开始)
- [Demo 演示](#Demo-演示)
- [Download 下载](#Download-下载)
- [Docs 文档](#Docs-文档)
- [License 许可证](#License-许可证)
- [Thanks 感谢](#Thanks-感谢)
- [Introduction 简介](#introduction-简介)
- [Quickstart 快速开始](#quickstart-快速开始)
- [Demo 演示](#demo-演示)
- [Download 下载](#download-下载)
- [Docs 文档](#docs-文档)
- [License 许可证](#license-许可证)
- [Todo 后续功能](#todo-后续功能)
- [Thanks 感谢](#thanks-感谢)
## Introduction 简介
@ -47,6 +48,8 @@ Let's start: http://localhost:8090
[SNAIL BLOG](https://slogc.cc)
[宋浩志博客](http://songhaozhi.com/)
## Download 下载
[Download](https://github.com/ruibaby/halo/releases)
@ -61,6 +64,12 @@ Let's start: http://localhost:8090
[![license](https://img.shields.io/github/license/ruibaby/halo.svg)](https://github.com/ruibaby/halo/blob/master/LICENSE)
## Todo 后续功能
- [ ] 文章阅读统计
- [ ] 文章顶置
- [ ] 集成又拍云,七牛云等云服务
## Thanks 感谢
Halo的诞生离不开下面这些项目

View File

@ -11,6 +11,7 @@ import com.sun.syndication.io.WireFeedOutput;
import io.github.biezhi.ome.OhMyEmail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
@ -644,4 +645,58 @@ public class HaloUtil {
}
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;
}
}

View File

@ -3,10 +3,7 @@ package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.*;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.service.TagService;
import cc.ryanc.halo.service.*;
import cc.ryanc.halo.util.HaloUtil;
import cc.ryanc.halo.web.controller.core.BaseController;
import lombok.extern.slf4j.Slf4j;
@ -24,6 +21,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
@ -49,6 +47,9 @@ public class PostController extends BaseController{
@Autowired
private LogsService logsService;
@Autowired
private OptionsService optionsService;
@Autowired
private HttpServletRequest request;
@ -162,7 +163,6 @@ public class PostController extends BaseController{
post.setTags(tags);
}
postService.saveByPost(post);
log.info("已发表新文章:"+post.getPostTitle());
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
}catch (Exception e){
log.error("未知错误:{0}",e.getMessage());
@ -271,4 +271,26 @@ public class PostController extends BaseController{
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_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;
}
}

View File

@ -133,7 +133,12 @@
</span>
</label>
<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>
@ -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() {
var native = $('input:radio[value=native]:checked').val();
var valine = $('input:radio[value=valine]:checked').val();

View File

@ -104,6 +104,17 @@
</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">
<label for="anatoleStyleHitokoto" class="col-sm-4 control-label">博客描述开启一言:</label>
<div class="col-sm-8">

View File

@ -22,6 +22,9 @@
<div class="by_halo">
<a href="https://github.com/ruibaby/halo" target="_blank">Proudly published with Halo&#65281;</a>
</div>
<div class="footer_text">
${options.blog_footer_info?if_exists}
</div>
</a>
</div>
</div>

View File

@ -17,6 +17,13 @@
<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 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>
<body>
</#macro>