Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
模板日志支持导出普通样式以及日志显示样式优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ShunCai committed Dec 8, 2021
1 parent 5f1cd7d commit c783d06
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/export/js/blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $(function () {
widthUnit: "%",
sortable: true,
formatter: (value, row) => {
return '<a href="info.html?blogId={0}" >{1}</a> '.format(row.blogid, value);
return '<a href="info.html?blogId={0}" >{1}</a> '.format(row.blogid || row.blogId, value);
}
}, {
field: 'category',
Expand Down
4 changes: 2 additions & 2 deletions src/export/js/diaries.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$(function () {
$(function() {
// 初始化日志表格
API.Utils.initTable("diaries-table", [{
checkbox: true,
Expand All @@ -12,7 +12,7 @@ $(function () {
widthUnit: "%",
sortable: true,
formatter: (value, row) => {
return '<a href="info.html?blogId={0}" >{1}</a> '.format(row.blogid, value);
return '<a href="info.html?blogId={0}" >{1}</a> '.format(row.blogid || row.blogId, value);
}
}, {
field: 'category',
Expand Down
71 changes: 64 additions & 7 deletions src/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,44 @@ API.Utils = {
items_a = items_a || [];
items_b = items_b || [];
return items_a.concat(items_b);
},

/**
* 加载页面
* @param {Object} pageDom 页面DOM
* @returns
*/
loadPage(pageDom) {
return new Promise(function(resolve, reject) {
pageDom.ready(function() {
resolve(pageDom);
});
});
},

/**
* 读取页面DOM变量的值
* @param {Object} jqPageDom 页面DOM元素
* @param {RegExp} regexp 正则
* @returns
*/
readScriptVar(jqPageDom, regexp) {
let targetVarValue = null;
if (!jqPageDom) {
return null;
}
// 获得网页中的指定脚本中变量的值
const scripts = [];
scripts.push(...jqPageDom.filter('script'));
scripts.push(...jqPageDom.find('script'));
for (const domScript of scripts) {
const text = $(domScript).text();
targetVarValue = regexp.exec(text);
if (targetVarValue != null) {
break;
}
}
return targetVarValue;
}
};

Expand Down Expand Up @@ -1902,6 +1940,25 @@ API.Blogs = {
"qzonetoken": QZone.Common.Config.token || API.Utils.getQZoneToken()
}
return API.Utils.get(QZone_URLS.VISITOR_SINGLE_LIST_URL, params);
},

/**
* 读取日志DOM读取详细信息
* @param {Object} jqPageDom
*/
readDetailInfo(jqPageDom) {
// 获得网页中的日志JSON数据
const blogData = API.Utils.readScriptVar(jqPageDom, /var g_oBlogData\s+=\s+({[\s\S]+});\s/);
return blogData && JSON.parse(blogData[1]).data || null;
},

/**
* 是否为模板日志
* @param {Object} item 日志信息
* @returns
*/
isTemplateBlog(item) {
return item.exblogtype == 2 || item.blogType;
}

};
Expand Down Expand Up @@ -3377,13 +3434,13 @@ API.Shares = {
continue;
}
$li.find('script').each(function() {
const text = $(this).text();
if (text.indexOf('shareInfos.push') > -1) {
eval('window.infoJson=' + /[\s\S]+shareInfos.push\((\{[\s\S]+\})\);[\s\S]+/.exec(text)[1]);
return false;
}
})
// 分享显示区
const text = $(this).text();
if (text.indexOf('shareInfos.push') > -1) {
eval('window.infoJson=' + /[\s\S]+shareInfos.push\((\{[\s\S]+\})\);[\s\S]+/.exec(text)[1]);
return false;
}
})
// 分享显示区
const $contentDiv = $($infoDiv.find('div.mod_conts._share_desc_cont'));
// 分享描述
const $temp_desc = $($contentDiv.find('div.mod_details.lbor > div.mod_brief > p.c_tx3.comming'));
Expand Down
31 changes: 15 additions & 16 deletions src/js/modules/blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ API.Blogs.getAllContents = async(items) => {
await API.Blogs.getInfo(item.blogId).then(async(data) => {
// 添加成功提示
indicator.addSuccess(data);
let blogPage = jQuery(data);
let blogData = null;
// 获得网页中的日志JSON数据
blogPage.find('script').each(function() {
let t = $(this).text();
if (t.indexOf('g_oBlogData') !== -1) {
let dataM = /var g_oBlogData\s+=\s+({[\s\S]+});\s/;
blogData = dataM.exec(t);
if (blogData != null) {
return false;
}
}
})
if (blogData != null) {
item = JSON.parse(blogData[1]).data;
}
// 加载日志页面
// const blogPage = await API.Utils.loadPage(jQuery(data)).catch((e) => console.error('读取日志内容失败', item, e));
const blogPage = jQuery(data);

// 基于DOM获取详细信息
item = API.Blogs.readDetailInfo(blogPage) || item;

// 获得网页中的日志正文
const $detailBlog = blogPage.find("#blogDetailDiv:first");

// 是否为模板日志
if (API.Blogs.isTemplateBlog(item)) {
// 模板日志,日志内容在变量中
const reg_res = API.Utils.readScriptVar(blogPage, /var g_oBlogContent\s+=\s+'([\s\S]+\/div>)';/);
eval((reg_res && reg_res[0] || '').replace('var g_oBlogContent', 'window.g_oBlogContent'))
$detailBlog.html(window.g_oBlogContent);
}

// 添加原始HTML
item.html = API.Utils.utf8ToBase64($detailBlog.html());

Expand Down
2 changes: 1 addition & 1 deletion src/templates/bloginfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2 id="blog_title" class="text-warning">日志标题</h2>
<span id="blog_time" class="text-muted">发布时间</span>
</div>
</div>
<article id="blog_content" class="mt-3">
<article id="blog_content" class="mt-3 p-2">
日志内容
</article>
<div id="comments_html">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/bloginfo_static.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2 id="blog_title" class="text-warning"><%:=blog.custom_title%></h2>
<span id="blog_time" class="text-muted"><%:=API.Utils.formatDate(blog.pubtime)%></span>
</div>
</div>
<article id="blog_content" class="mt-3">
<article id="blog_content" class="mt-3 p-2">
<%:=API.Utils.base64ToUtf8(blog.custom_html)%>
</article>
<div id="comments_html">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/diaryinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2 id="blog_title" class="text-warning">日记标题</h2>
<span id="blog_time" class="text-muted">发布时间</span>
</div>
</div>
<article id="blog_content" class="mt-3">
<article id="blog_content" class="mt-3 p-2">
日记内容
</article>
<div id="comments_html">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/diaryinfo_static.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2 id="blog_title" class="text-warning"><%:=blog.custom_title%></h2>
<span id="blog_time" class="text-muted"><%:=API.Utils.formatDate(blog.pubtime)%></span>
</div>
</div>
<article id="blog_content" class="mt-3">
<article id="blog_content" class="mt-3 p-2">
<%:=API.Utils.base64ToUtf8(blog.custom_html)%>
</article>
<div id="comments_html">
Expand Down

0 comments on commit c783d06

Please sign in to comment.