← SEARCHABLE ARCHIVE
Web · 2026-07-06

部落格網路功能總結

目前部落格如何加載和顯示帖子

INTERACTIVE READING MODE →

本部落格網路功能摘要

// data.js
//管理部落格類別和貼文列表
//在categoryMap中輸入類別名稱,
//posts 陣列包含實際文章的標題、摘要、檔案名稱和標籤。

const categoryMap = {
    'CPP': { name: 'C / C++' },
    'CS': { name: 'Computer Science' },
    'WEB': { name: 'Web' },
    'NTT': { name: 'Nand2Tetris' }
};

const posts = [
    {
        id: 110001,
        category: 'WEB',
        date: '2026-05-20',
        title: '部落格網路功能總結',
        summary: '目前部落格如何加載和顯示帖子',
        fileName: 'WEBBlogFeature.md',
        tags: ['Web', 'Blog']
    }
];
// app.js
//使用哈希路由更改螢幕
//例子:
//#home:主螢幕
//#category/WEB/1 : WEB 類別頁 1
//#post/110001:具體帖子

function router() {
    const hash = location.hash || '#home';

    if (hash === '#home') {
        renderHome();
    } else if (hash.startsWith('#category/')) {
        renderCategory(hash);
    } else if (hash.startsWith('#post/')) {
        renderPost(hash);
    }
}
//後載入方法
//在 posts 陣列中尋找 fileName,
//使用 fetch 匯入 posts 資料夾中的 Markdown 檔案並將其顯示在螢幕上。

fetch(`posts/${post.fileName}`)
    .then(response => response.text())
    .then(markdown => {
        document.querySelector('#content').innerHTML = marked.parse(markdown);
    });
<!-- 怎麼寫 -->
<!-- 1. 在 posts 資料夾中建立一個 Markdown 檔案。 -->
<!-- 2.將post資訊加入data.js中的posts陣列中 -->
<!-- 3. 類別和標籤過濾器根據類別和標籤值自動工作。 -->

# 標題

文字是用 Markdown 寫的。

```cpp
// 也可以使用程式碼區塊
int main() {
    return 0;
}
```