/* Aifit — News & SNS section
* 新着情報/ブログ/コラムを WordPress REST API からブラウザfetchで自動表示
* + 本日の訃報バンド(外部リンク)+ Facebook ページプラグイン + Instagram 導線
*/
(function () {
const { useState, useEffect, useRef } = React;
const Icon = window.Icon;
const API = "https://saiki-sousai.com/wp-json/wp/v2/";
const FEEDS = [
{ key: "news", base: "news", label: "新着情報", all: "https://saiki-sousai.com/news/" },
{ key: "blog", base: "posts", label: "ブログ", all: "https://saiki-sousai.com/blog/" },
{ key: "column", base: "column", label: "コラム", all: "https://saiki-sousai.com/column/" },
];
const FUHO = "https://www.27900.jp/funeral/Top?access_key=455873795032376e434e6733572b6434746668626e6f6378634a533077396574594b53554c2b416b312f6f3d";
// Behold(無料) で @saiki_group を連携後、発行されたフィードIDをここに入れるだけで自動フィードが有効化される。
// 空文字の間は Instagram 公式プロフィールへの導線を表示する。
const BEHOLD_FEED_ID = "EnZkB2RP82JverKyuj6G";
function decode(html) {
const t = document.createElement("textarea");
t.innerHTML = html || "";
return t.value;
}
function fmtDate(d) {
try {
const x = new Date(d);
return x.getFullYear() + "." + String(x.getMonth() + 1).padStart(2, "0") + "." + String(x.getDate()).padStart(2, "0");
} catch (e) { return ""; }
}
// アイキャッチ(the_thumb 相当)→ 本文/抜粋中の最初の画像、の順で取得
function pickImage(p) {
const m = p._embedded && p._embedded["wp:featuredmedia"] && p._embedded["wp:featuredmedia"][0];
if (m && m.source_url) return m.source_url;
const html = (p.content && p.content.rendered) || (p.excerpt && p.excerpt.rendered) || "";
const mm = html.match(/]+src=["']([^"']+)["']/i);
return mm ? mm[1] : null;
}
function Feed({ base, label, all }) {
const [posts, setPosts] = useState(null); // null=loading, []=empty/error
useEffect(() => {
let alive = true;
fetch(API + base + "?_embed&per_page=4")
.then((r) => (r.ok ? r.json() : Promise.reject(r.status)))
.then((d) => { if (alive) setPosts(Array.isArray(d) ? d : []); })
.catch(() => { if (alive) setPosts([]); });
return () => { alive = false; };
}, [base]);
return (
読み込み中…
} {posts && posts.length === 0 && ( {label}の一覧を見る → )} {posts && posts.map((p, i) => { const img = pickImage(p); return ( {img ?