从 Hexo 安知鱼主题迁移过来后,许多旧的美化教程都不适用了,网上搜搜也找不到多少适配的。
研究了两三天后,已经移植了不少,本期是魔改教程铺垫的第一期,后续会发正式魔改教程。
那时候魔改印象最深刻的还是柳神的两个项目
具体使用教程请见仓库的 readme 文档,及柳神博客的相关教程。
朋友圈精简版 friend.json 适配
根目录新建文件夹 api,里面创建friend.php文件

文件内容如下
<?php
require_once dirname(__FILE__) . '/../config.inc.php';
$db = \Typecho\Db::get();
try {
$query = $db->select('title', 'url', 'logo')
->from('table.friends')
->where('status = ?', 1);
$rows = $db->fetchAll($query);
$friends = [];
foreach ($rows as $row) {
$friends[] = [
$row['title'],
$row['url'],
$row['logo'] ?? ''
];
}
$output = [
'friends' => $friends
];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (\Typecho\Db\Exception $e) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
}
可以使用伪静态实现静态化 json
规则如下
rewrite ^/friend.json$ /api/friend.php;

友链状态检测 flink_count.json 适配
根目录新建文件夹 api,里面创建flink_count.php文件

文件内容如下
<?php
require_once dirname(__FILE__) . '/../config.inc.php';
$db = \Typecho\Db::get();
try {
$query = $db->select('title', 'url', 'logo', 'description')
->from('table.friends')
->where('status = ?', 1);
$rows = $db->fetchAll($query);
$link_list = [];
foreach ($rows as $row) {
$name = $row['title'];
$link = $row['url'];
$avatar = $row['logo'] ?? '';
$descr = $row['description'];
$siteshot = "https://v2.xxapi.cn/api/screenshot?url=" . urlencode($link) . "&return=302";
$link_list[] = [
"name" => $name,
"link" => $link,
"avatar" => $avatar,
"descr" => $descr,
"siteshot" => $siteshot
];
}
$length = count($link_list);
$output = [
"link_list" => $link_list,
"length" => $length
];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (\Typecho\Db\Exception $e) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
}
可以使用伪静态实现静态化 json
规则如下
rewrite ^/flink_count.json$ /api/flink_count.php;

评论加载中...