Hexo 批量设置文章封面图
Hexo 批量设置文章封面图
本人有一堆编号不连续且形如 p123.webp
的封面图,现在需要把他们全写进默认封面图设置里。
然而本人只会一个笨办法,那就是写个 C++ 程序自动搞,并写一篇文章记录一下防止下次还要重写一个。
使用方法就是开一个终端 ls
一下,然后把输出的结果全部扔到输入文件里就好了。
时间复杂度 \(O(nL \log nL)\) ,其中 \(L\) 为字符串长度,\(n\) 为图片的总数量。
代码:(注意开了文件读写)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
template<typename T> void up(T &x, T y) { x < y ? x = y : 0; }
template<typename T> void down(T &x, T y) { x > y ? x = y : 0; }
#define rep(i, a, b) for(int i = (a), i##END = (b); i <= i##END; i++)
#define Rep(i, a, b) for(int i = (a), i##END = (b); i >= i##END; i--)
#define N ((int)())
string str;
vector<string> vec;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen("check.in","r",stdin);
freopen("check.out","w",stdout);
while(cin >> str)
{
if(str.size() > 3 && str[0] == 'p' && isdigit(str[1]) > 0)
vec.push_back(str);
}
sort(vec.begin(), vec.end(), [](const string &a, const string &b){
if(a.size() != b.size()) return a.size() < b.size();
else { return a < b; }
});
for(auto i : vec) cout << "- /qwq/img/" << i << '\n';
return 0;
}
输出的效果(部分)如下
- /qwq/img/p1.webp
- /qwq/img/p8.webp
- /qwq/img/p26.webp
- /qwq/img/p40.webp
- /qwq/img/p52.webp
然后把这些丢到主题配置文件里改改就好了。
本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 Q779’s Blog!




