Skip to content

Commit

Permalink
chore(deps): support hexo 4.2.0 (tea3#22)
Browse files Browse the repository at this point in the history
* In hexo 4.2.0 Locals class use hexo-util
* hexojs/hexo#3996
  • Loading branch information
yoshinorin committed Dec 24, 2019
1 parent 5f782be commit 8d84376
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ module.exports = ( hexo ) => {
// load hexo@3.2's cache
// --------------------------------------------
// If the article is not updated, hexo internally caches the previous data (db.json).
if (hexo && hexo.locals && hexo.locals.cache && hexo.locals.cache.posts.length && hexo.locals.cache.posts.data[0].popularPost_tmp_gaData && hexo.locals.cache.posts.data[hexo.locals.cache.posts.length - 1].popularPost_tmp_gaData) {
if (hexo && hexo.locals && hexo.locals.cache.cache && hexo.locals.cache.cache.posts.length && hexo.locals.cache.cache.posts.data[0].popularPost_tmp_gaData && hexo.locals.cache.cache.posts.data[hexo.locals.cache.cache.posts.length - 1].popularPost_tmp_gaData) {
let tmp_gaData = hexo.config.popularPosts.tmp.gaData
hexo.config.popularPosts.tmp.postPath = null
hexo.config.popularPosts.tmp.postPath = []
hexo.config.popularPosts.tmp.gaData = null
hexo.config.popularPosts.tmp.gaData = []

for (let v=0; v<hexo.locals.cache.posts.length; v++) {
for (let v=0; v<hexo.locals.cache.cache.posts.length; v++) {
// PV update
if (hexo.config.popularPosts.tmp.isGaUpdate) {
for (let w=0; w<tmp_gaData.length; w++) {
if (root + hexo.locals.cache.posts.data[v].popularPost_tmp_gaData.path == tmp_gaData[w].path) {
hexo.locals.cache.posts.data[v].popularPost_tmp_gaData.pv = tmp_gaData[w].pv;
hexo.locals.cache.posts.data[v].popularPost_tmp_gaData.totalPV = tmp_gaData[w].totalPV;
if (root + hexo.locals.cache.cache.posts.data[v].popularPost_tmp_gaData.path == tmp_gaData[w].path) {
hexo.locals.cache.cache.posts.data[v].popularPost_tmp_gaData.pv = tmp_gaData[w].pv;
hexo.locals.cache.cache.posts.data[v].popularPost_tmp_gaData.totalPV = tmp_gaData[w].totalPV;
break;
}
}
}

hexo.config.popularPosts.tmp.gaData.push(hexo.locals.cache.posts.data[v].popularPost_tmp_gaData)
if (hexo.locals.cache.posts.data[v].popularPost_tmp_postPath)hexo.config.popularPosts.tmp.postPath.push(hexo.locals.cache.posts.data[v].path)
hexo.config.popularPosts.tmp.gaData.push(hexo.locals.cache.cache.posts.data[v].popularPost_tmp_gaData)
if (hexo.locals.cache.cache.posts.data[v].popularPost_tmp_postPath)hexo.config.popularPosts.tmp.postPath.push(hexo.locals.cache.cache.posts.data[v].path)
}
gaData = hexo.config.popularPosts.tmp.gaData
tmp_gaData = null
Expand All @@ -52,7 +52,7 @@ module.exports = ( hexo ) => {
// -----------------------------------------------
// When you use the hexo clean command, the internal cache of hexo is cleared.
// In this case , merge the updated article data and plugin's cache data (e.g. hexo-rpp-cached.json).
} else if (hexo && hexo.locals && hexo.locals.cache && hexo.locals.cache.posts.length && !hexo.locals.cache.posts.data[0].popularPost_tmp_gaData && cache_path) {
} else if (hexo && hexo.locals && hexo.locals.cache.cache && hexo.locals.cache.cache.posts.length && !hexo.locals.cache.cache.posts.data[0].popularPost_tmp_gaData && cache_path) {
for (let i = 0; i < gaData.length; i++) {
let matchedPath = true
for (let k = 0; k < hexo.config.popularPosts.tmp.postPath.length; k++) {
Expand All @@ -66,7 +66,7 @@ module.exports = ( hexo ) => {
// -----------------------------------------------
// When you use the hexo clean command, the internal cache of hexo is cleared.
// In this case , merge the postPath data
} else if (hexo && hexo.locals && hexo.locals.cache && hexo.locals.cache.posts.length && hexo.locals.cache.posts.data[0].popularPost_tmp_gaData && !hexo.locals.cache.posts.data[hexo.locals.cache.posts.length - 1].popularPost_tmp_gaData) {
} else if (hexo && hexo.locals && hexo.locals.cache.cache && hexo.locals.cache.cache.posts.length && hexo.locals.cache.cache.posts.data[0].popularPost_tmp_gaData && !hexo.locals.cache.cache.posts.data[hexo.locals.cache.cache.posts.length - 1].popularPost_tmp_gaData) {
if (hexo.config.popularPosts.tmp.postPath.length == 0) {
for (let i = 0; i < gaData.length; i++) {
hexo.config.popularPosts.tmp.postPath.push(gaData[i].path)
Expand Down
14 changes: 7 additions & 7 deletions lib/list-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ module.exports.getList = (inOptions, inPost, inHexo) => {

// load hexo@3.2's cache
// --------------------------------------------
if (!config.popularPosts.tmp.cache_path && inHexo && inHexo.locals && inHexo.locals.cache && inHexo.locals.cache.posts.length && inHexo.locals.cache.posts.data[0].popularPost_tmp_gaData) {
if (!config.popularPosts.tmp.cache_path && inHexo && inHexo.locals && inHexo.locals.cache.cache && inHexo.locals.cache.cache.posts.length && inHexo.locals.cache.cache.posts.data[0].popularPost_tmp_gaData) {
let tmp_gaData = config.popularPosts.tmp.gaData
config.popularPosts.tmp.postPath = null
config.popularPosts.tmp.postPath = []
config.popularPosts.tmp.gaData = null
config.popularPosts.tmp.gaData = []
for (let i = 0; i < inHexo.locals.cache.posts.length; i++) {
for (let i = 0; i < inHexo.locals.cache.cache.posts.length; i++) {
// PV update
if (config.popularPosts.tmp.isGaUpdate) {
for (k=0; k<tmp_gaData.length; k++) {
if (inHexo.locals.cache.posts.data[i].popularPost_tmp_gaData.path == tmp_gaData[k].path) {
inHexo.locals.cache.posts.data[i].popularPost_tmp_gaData.pv = tmp_gaData[k].pv
inHexo.locals.cache.posts.data[i].popularPost_tmp_gaData.totalPV = tmp_gaData[k].totalPV
if (inHexo.locals.cache.cache.posts.data[i].popularPost_tmp_gaData.path == tmp_gaData[k].path) {
inHexo.locals.cache.cache.posts.data[i].popularPost_tmp_gaData.pv = tmp_gaData[k].pv
inHexo.locals.cache.cache.posts.data[i].popularPost_tmp_gaData.totalPV = tmp_gaData[k].totalPV
break
}
}
}

config.popularPosts.tmp.gaData.push(inHexo.locals.cache.posts.data[i].popularPost_tmp_gaData)
if (inHexo.locals.cache.posts.data[i].popularPost_tmp_postPath)config.popularPosts.tmp.postPath.push(inHexo.locals.cache.posts.data[i].path)
config.popularPosts.tmp.gaData.push(inHexo.locals.cache.cache.posts.data[i].popularPost_tmp_gaData)
if (inHexo.locals.cache.cache.posts.data[i].popularPost_tmp_postPath)config.popularPosts.tmp.postPath.push(inHexo.locals.cache.cache.posts.data[i].path)
}
tmp_gaData = null
}
Expand Down
8 changes: 4 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ module.exports.orverrideTmp = (inGaData, inHexo) => {
// load hexo@3.2's cache
// ----------------------------------------------
let isUseHexosCache = false
if (( !inGaData || inGaData == []) && inHexo && inHexo.locals && inHexo.locals.cache && inHexo.locals.cache.posts.length && inHexo.locals.cache.posts.data[0].popularPost_tmp_gaData) {
if (( !inGaData || inGaData == []) && inHexo && inHexo.locals && inHexo.locals.cache.cache && inHexo.locals.cache.cache.posts.length && inHexo.locals.cache.cache.posts.data[0].popularPost_tmp_gaData) {
isUseHexosCache = true
gaData_tmp = null
gaData_tmp = []
let postPath_temp = []
for (let v=0; v<inHexo.locals.cache.posts.length; v++) {
gaData_tmp.push(inHexo.locals.cache.posts.data[v].popularPost_tmp_gaData)
if (inHexo.locals.cache.posts.data[v].popularPost_tmp_postPath)postPath_temp.push(inHexo.locals.cache.posts.data[v].path)
for (let v=0; v<inHexo.locals.cache.cache.posts.length; v++) {
gaData_tmp.push(inHexo.locals.cache.cache.posts.data[v].popularPost_tmp_gaData)
if (inHexo.locals.cache.cache.posts.data[v].popularPost_tmp_postPath)postPath_temp.push(inHexo.locals.cache.cache.posts.data[v].path)
}

inHexo.config.popularPosts.tmp = Object.assign( {},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"eslint": "^4.12.0",
"eslint-config-google": "^0.9.1",
"hexo": "^3.3.9",
"hexo": "^4.2.0",
"intelli-espower-loader": "^1.0.1",
"istanbul": "^0.4.5",
"mocha": "^4.0.1",
Expand Down

0 comments on commit 8d84376

Please sign in to comment.