getPosts('/blog/', null); // 最新の5件に制限 $posts = array_slice($posts, 0, 5); // サイトのドメインを取得 $domain = $_SERVER['HTTP_HOST']; $baseUrl = 'https://'.$domain; // 現在の日時(RFC3339形式) $published = date('c'); // XMLヘッダーとコンテンツタイプを設定 header('Content-Type: application/atom+xml; charset=utf-8'); // Atomフィードの開始部分 echo ''."\n"; echo ''."\n"; // フィードの基本情報 echo ' '.SITEINFO['title'].''."\n"; echo ' '."\n"; echo ' '."\n"; echo ' '.$baseUrl.'/'."\n"; echo ' '.$published.''."\n"; echo ' '.$published.''."\n"; echo ' '."\n"; echo ' '.SITEINFO['title'].''."\n"; echo ' '."\n"; // 各エントリー(記事) foreach ($posts as $post) { // 記事の本文を取得(プレーンテキスト) $path = ROOT.'/blog/'.$post['slug'].'.md'; $content = ''; $postPublished = date('c', strtotime($post['date'])); if (file_exists($path)) { $fileContent = file_get_contents($path); $parts = explode('----', $fileContent, 2); if (count($parts) > 1) { // 本文をHTMLとして準備 $md = new Markdown($post['slug'], '/blog/'); $content = $md->parse(); // HTMLタグを取り除かないようにCDATAで囲む $content = ''; } } echo ' '."\n"; echo ' '.htmlspecialchars($post['title']).''."\n"; echo ' '."\n"; echo ' '.$baseUrl.'/blog/'.$post['slug'].''."\n"; echo ' '.$postPublished.''."\n"; // カテゴリ(タグ) if (isset($post['category']) && is_array($post['category'])) { foreach ($post['category'] as $category) { echo ' '."\n"; } } // 本文(要約または全文) echo ' '.$content.''."\n"; echo ' '."\n"; } // フィードの終了 echo ''; exit; } catch (\Exception $e) { header('Content-Type: text/plain; charset=utf-8'); echo 'フィードの作成に失敗: '.$e->getMessage(); exit; } } }