質問編集履歴
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,7 +21,64 @@
|
|
21
21
|
### 該当のソースコード
|
22
22
|
|
23
23
|
```
|
24
|
+
document.addEventListener("DOMContentLoaded", function () {
|
25
|
+
(async function loadNoteRSS() {
|
24
|
-
|
26
|
+
try {
|
27
|
+
const apiUrl = "https://api.rss2json.com/v1/api.json?rss_url=https://note.com/visiongram/m/m54d8edffc68f/rss";
|
28
|
+
|
29
|
+
const response = await axios.get(apiUrl);
|
30
|
+
const data = response.data;
|
31
|
+
|
32
|
+
if (data.status === "ok") {
|
33
|
+
let html = "";
|
34
|
+
|
35
|
+
for (const item of data.items) {
|
36
|
+
const dateStr = new Date(item.pubDate).toLocaleDateString("ja-JP", {
|
37
|
+
year: "numeric",
|
38
|
+
month: "numeric",
|
39
|
+
day: "numeric"
|
40
|
+
});
|
41
|
+
|
42
|
+
const imgMatch = item.description.match(/<img.*?src="(https:\/\/assets\.st-note\.com\/.*?)"/);
|
43
|
+
const thumbnail = imgMatch ? imgMatch[1] : "_assets/img/noimage.jpg";
|
44
|
+
|
45
|
+
html += `
|
46
|
+
<li class="item_note">
|
47
|
+
<a class="rss-link" href="${item.link}" target="_blank" rel="noopener noreferrer">
|
48
|
+
<section>
|
49
|
+
<p class="date">${dateStr}</p>
|
50
|
+
<div class="detail">
|
51
|
+
<div class="txts">
|
52
|
+
<h3>${item.title}</h3>
|
53
|
+
</div>
|
54
|
+
<div class="img">
|
55
|
+
<img src="${thumbnail}" alt="${item.title}">
|
56
|
+
</div>
|
57
|
+
</div>
|
58
|
+
</section>
|
59
|
+
</a>
|
60
|
+
</li>
|
61
|
+
`;
|
62
|
+
}
|
63
|
+
const container = document.getElementById("items");
|
64
|
+
if (container) {
|
65
|
+
container.innerHTML = html + container.innerHTML;
|
66
|
+
}
|
67
|
+
|
68
|
+
if (data.items.length <= 3) {
|
69
|
+
document.querySelectorAll(".btn_more").forEach(el => el.classList.add("hide_sp"));
|
70
|
+
}
|
71
|
+
if (data.items.length <= 9) {
|
72
|
+
document.querySelectorAll(".btn_more").forEach(el => el.classList.add("hide_pc"));
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
console.error("RSSデータの取得に失敗しました:", data.message);
|
76
|
+
}
|
77
|
+
} catch (error) {
|
78
|
+
console.error("RSSの読み込み中にエラーが発生しました:", error);
|
79
|
+
}
|
80
|
+
})();
|
81
|
+
});
|
25
82
|
```
|
26
83
|
|
27
84
|
### 試したこと・調べたこと
|