Skip to content

Commit 55787e5

Browse files
author
y-yamasaki
committed
マークダウン読み込み調整
1 parent d47545c commit 55787e5

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

assets/css/base.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ html {
3131
scroll-behavior: smooth;
3232
}
3333

34+
html,
35+
body {
36+
height: 100%;
37+
}
38+
3439
body {
3540
margin: 0;
3641
font-family: var(--font-body);

assets/js/blog.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ document.addEventListener("DOMContentLoaded", async () => {
311311
detailSection.style.display = "";
312312

313313
const post = posts.find((p) => p.id === id);
314-
315314
if (!post) {
316315
detailTitle.textContent =
317316
"記事が見つかりませんでした";
@@ -357,16 +356,15 @@ document.addEventListener("DOMContentLoaded", async () => {
357356
try {
358357
const res = await fetch(post.contentPath);
359358
if (!res.ok) throw new Error(res.statusText);
360-
const md = await res.text();
359+
const markdown = await res.text();
360+
const bodyOnly = stripFrontMatter(markdown);
361361

362-
if (typeof marked === "undefined") {
363-
detailBody.textContent =
364-
"Markdown パーサが読み込めていません。";
365-
return;
362+
// marked.js があれば使う / 無ければプレーンテキストで表示
363+
if (window.marked) {
364+
detailBody.innerHTML = marked.parse(bodyOnly);
365+
} else {
366+
detailBody.textContent = bodyOnly;
366367
}
367-
368-
const bodyOnly = stripFrontMatter(md);
369-
detailBody.innerHTML = marked.parse(bodyOnly);
370368
} catch (err) {
371369
console.error(
372370
"記事本文の読み込みに失敗しました:",

assets/js/portfolio.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,25 +313,26 @@ document.addEventListener("DOMContentLoaded", async () => {
313313
detailSection.style.display = "";
314314

315315
const work = works.find((w) => w.id === id);
316-
317316
if (!work) {
318317
detailTitle.textContent =
319318
"作品が見つかりませんでした";
320319
detailMeta.textContent = "";
321320
detailBody.textContent =
322-
"指定された作品 ID は存在しません。";
321+
"指定された ID の作品が見つかりません。";
322+
if (detailTags) detailTags.textContent = "";
323323
return;
324324
}
325325

326-
detailTitle.textContent = work.title;
327-
326+
// タイトル・メタ
327+
detailTitle.textContent = work.title || "(無題)";
328328
const metaParts = [];
329329
if (work.role) metaParts.push(`Role: ${work.role}`);
330330
if (work.tech) metaParts.push(`Tech: ${work.tech}`);
331331
if (work.platform)
332332
metaParts.push(`Platform: ${work.platform}`);
333333
detailMeta.textContent = metaParts.join(" / ");
334334

335+
// タグ表示(省略可)
335336
if (detailTags) {
336337
detailTags.innerHTML = "";
337338
const tags = Array.isArray(work.tags)
@@ -360,15 +361,13 @@ document.addEventListener("DOMContentLoaded", async () => {
360361
try {
361362
const res = await fetch(work.contentPath);
362363
if (!res.ok) throw new Error(res.statusText);
363-
const md = await res.text();
364-
365-
if (typeof marked === "undefined") {
366-
detailBody.textContent =
367-
"Markdown パーサが読み込めていません。";
368-
return;
364+
const markdown = await res.text();
365+
const bodyOnly = stripFrontMatter(markdown);
366+
if (window.marked) {
367+
detailBody.innerHTML = marked.parse(bodyOnly);
368+
} else {
369+
detailBody.textContent = bodyOnly;
369370
}
370-
const bodyOnly = stripFrontMatter(md);
371-
detailBody.innerHTML = marked.parse(bodyOnly);
372371
} catch (err) {
373372
console.error("作品詳細の読み込みに失敗:", err);
374373
detailBody.textContent =

0 commit comments

Comments
 (0)