Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这个cache是不是应该放在if的外面,不然有可能和历史的文章重复? #76

Open
Asutorufa opened this issue Dec 4, 2024 · 8 comments

Comments

@Asutorufa
Copy link

Asutorufa commented Dec 4, 2024

model.cachePostAbbrlink(data.source, abbrlink)

感觉是需要old_cache和new_cache分开,然后在写入文件前再判断下old_cache中有没有。

@yqs112358
Copy link
Contributor

yqs112358 commented Dec 8, 2024

没太看明白😂,大佬可以举个例子吗

@Asutorufa
Copy link
Author

Asutorufa commented Dec 8, 2024

没太看明白😂,大佬可以举个例子吗

@yqs112358
大概这个意思,写的可能不太准确,但意思差不多

let generateAbbrlink = function (data) {
                ...
                ...
        // calc abbrlinks
        if (!abbrlink || abbrlink == '0' || config.force) {
                ...
                ...
            model.cacheNewPostAbbrlink(data.source, abbrlink) // 如果是新文章,缓存到new_cache
        } else {
            model.cacheOldPostAbbrlink(data.source, abbrlink) // 旧文档,缓存到old_cache
        }
}


let writebackToFiles = function (data) {
        ...
        ...
        
    // avoid rewrite front-matter if the same abbrlink exists
    let abbrlink = model.getNewPostAbbrlink(data.source)
    if(!abbrlink)
        return data;
        
    // 新文章时,判断旧文档中是否已经有相同的link,如果有就再生成直到不重复
    abbrlink = model.uniqueAbbrlinkByOldCache(abbrlink); 
    
        ...
        ...
}

@yqs112358
Copy link
Contributor

喔,这边确实疏忽了,我看着改一下,感谢兄弟👍

@yqs112358
Copy link
Contributor

yqs112358 commented Dec 12, 2024

hexojs/hexo#5583
发了帖子问遍历posts,几天都没人鸟🫠话说哥们这方面有思路没 @Asutorufa

我的想法是,尽量在post_permalink里面就确定好abbrlink,避免到后面的before_post_render阶段再更新,这样应该比较符合语义。
但是这样的话需要在post_permalink及以前先遍历所有的posts来统计已存在的abbrlinks,目前还没找到合适的方法。。。hexo这API设计的也有点一言难尽

@Asutorufa
Copy link
Author

Asutorufa commented Dec 13, 2024

@yqs112358

我也不太熟悉这个流程,看了filter的文档,感觉写的模棱两可。
不过也许可以像这位兄弟一样直接操作db.json,反而更直观一点。
也不需要对db.json进行写操作,只需要拿到里面的历史文章的内容。

スクリーンショット 2024-12-13 11 28 08

@yqs112358
Copy link
Contributor

yqs112358 commented Dec 23, 2024

确实哈,我看一下
应该还可以。唯一的缺点是hexo clean之后第一次generate扫描不到这个db,如果这时候新增文章的话就可能碰到冲突。另外如果front-matter和DB里面不一致也会出现问题
都怪hexo这接口设计的。。。。唉

@yqs112358
Copy link
Contributor

yqs112358 commented Dec 23, 2024

@Asutorufa
哥们试一下?现在应该没问题了 #77

@yqs112358
Copy link
Contributor

merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants