2024-06-05 15:59:42 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 好物页面
|
|
|
|
*
|
|
|
|
* @package custom
|
|
|
|
*/
|
|
|
|
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
|
|
|
|
<?php $this->need('header.php'); ?>
|
|
|
|
<div class="site--main site--main__gears">
|
2024-06-05 16:50:26 +08:00
|
|
|
<header class="archive--header">
|
2024-06-05 15:59:42 +08:00
|
|
|
<h1 class="post--single__title"><?php $this->title() ?></h1>
|
|
|
|
<h2 class="post--single__subtitle"><?php $this->content(); ?></h2>
|
2024-06-05 16:50:26 +08:00
|
|
|
</header>
|
|
|
|
<div id=goods class="good--list"></div>
|
2024-06-05 15:59:42 +08:00
|
|
|
</div>
|
2024-06-05 16:50:26 +08:00
|
|
|
<style>
|
|
|
|
.img40 {
|
|
|
|
height: 137px;
|
|
|
|
width: auto;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<?php
|
|
|
|
// 检查是否存在自定义字段 'memos' 和 'memosID'
|
|
|
|
$memos = $this->fields->memos ? $this->fields->memos : 'https://memos.imsun.org';
|
|
|
|
$memosID = $this->fields->memosID ? $this->fields->memosID : '1';
|
|
|
|
$memostag = $this->fields->memostag ? $this->fields->memostag : '好物';
|
|
|
|
?>
|
2024-06-05 15:59:42 +08:00
|
|
|
<script>
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
memoGoods();
|
|
|
|
});
|
|
|
|
function memoGoods(e) {
|
|
|
|
let t = e || 12;
|
2024-06-05 16:50:26 +08:00
|
|
|
var n = "<?php echo $memos; ?>",
|
|
|
|
s = n + "/api/v1/memo?creatorId=<?php echo $memosID; ?>&limit=" + t + "&tag=<?php echo $memostag; ?>";
|
2024-06-05 15:59:42 +08:00
|
|
|
let i = 1;
|
|
|
|
const o = /\n/;
|
|
|
|
fetch(s).then(e => e.json()).then(e => {
|
|
|
|
let c = "";
|
|
|
|
for (var t, s, i, a, d, u, h, m, r = 0; r < e.length; r++) {
|
|
|
|
a = e[r].content.replace(`#好物 \n`, ""),
|
|
|
|
t = a.split(o),
|
|
|
|
i = t[0].replace(/!\[.*?\]\((.*?)\)/g, "$1"), // 图片链接
|
|
|
|
s = t[0].replace(/!\[(.*?)\]\(.*?\)/g, "$1"),
|
|
|
|
d = s.split(",")[0], // 商品名称
|
|
|
|
u = s.split(",")[1], // 价格
|
|
|
|
h = t[1].replace(/\[.*?\]\((.*?)\)/g, "$1"), // 商品链接
|
|
|
|
m = t[1].replace(/\[(.*?)\]\(.*?\)/g, "$1"), // 推荐理由
|
|
|
|
c +=
|
|
|
|
'<div class="good--item"><div class="img-spacer"><a href="'
|
|
|
|
+ h +
|
|
|
|
'" target="_blank"><img src="'
|
|
|
|
+ i +
|
2024-06-05 16:50:26 +08:00
|
|
|
'" class="img40"></a></div><div class="good--name"><div class="brand">'
|
|
|
|
+ d + '·' + m +'</div>'
|
|
|
|
+ u +
|
2024-06-05 15:59:42 +08:00
|
|
|
'</div></div>';
|
|
|
|
}
|
|
|
|
let f = document.querySelector("#goods");
|
|
|
|
f.innerHTML = c;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
2024-06-05 16:50:26 +08:00
|
|
|
<?php $this->need('footer.php'); ?>
|