Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

5.5 KB
Raw Blame
---
import { getCollection } from "astro:content";
import Container from "@/components/container.astro";
import Layout from "@/layouts/Layout.astro";
import { getFormattedDate } from "@/utils/all";
import { getLocalizedPath, getSiteLocale, siteCopy } from "@/i18n";

const entries = (await getCollection("blog", ({ data }) => !data.draft)).sort(
  (a, b) => Number(b.id === "evernote-migration-guide") - Number(a.id === "evernote-migration-guide")
    || b.data.publishDate.getTime() - a.data.publishDate.getTime(),
);

const locale = getSiteLocale(Astro.url.pathname);
const copy = siteCopy[locale].nav;

const blogUrl = new URL(Astro.url.pathname, Astro.site).toString();
const blogDescription =
  "EdgeEver 官方博客,记录 Cloudflare 自托管部署、印象笔记迁移、产品更新与 AI Agent 工作流。";

const blogJsonLd = {
  "@context": "https://schema.org",
  "@type": "CollectionPage",
  name: "EdgeEver Blog",
  url: blogUrl,
  inLanguage: "zh-CN",
  description: blogDescription,
};
---

<Layout title="博客" description={blogDescription} jsonLd={blogJsonLd}>
  <Container>
    <main class="mx-auto max-w-4xl py-16 md:py-24">
      <div class="mb-8">
        <p class="text-sm font-semibold text-brand-text">EdgeEver Blog</p>
        <h1 class="mt-3 text-4xl font-bold tracking-tight text-slate-900 md:text-5xl">
          博客
        </h1>
      </div>

      <!-- 标签筛选工具条 (全部默认为普通态,通过客户端 Script 激活) -->
      <div class="flex flex-wrap gap-2 mb-10 select-none">
        <a
          href={getLocalizedPath(locale, "/blog")}
          data-tag-btn="all"
          class="px-4 py-1.5 text-xs font-medium border rounded-full transition-all duration-200 cursor-pointer text-slate-600 bg-slate-50 border-slate-200 hover:bg-slate-100 hover:text-slate-900"
        >
          {copy.tagAll}
        </a>
        <a
          href={`${getLocalizedPath(locale, "/blog")}?tag=migration`}
          data-tag-btn="migration"
          class="px-4 py-1.5 text-xs font-medium border rounded-full transition-all duration-200 cursor-pointer text-slate-600 bg-slate-50 border-slate-200 hover:bg-slate-100 hover:text-slate-900"
        >
          🏷️ {copy.tagMigration}
        </a>
        <a
          href={`${getLocalizedPath(locale, "/blog")}?tag=mcp`}
          data-tag-btn="mcp"
          class="px-4 py-1.5 text-xs font-medium border rounded-full transition-all duration-200 cursor-pointer text-slate-600 bg-slate-50 border-slate-200 hover:bg-slate-100 hover:text-slate-900"
        >
          🤖 {copy.tagMcp}
        </a>
        <a
          href={`${getLocalizedPath(locale, "/blog")}?tag=self-hosted`}
          data-tag-btn="self-hosted"
          class="px-4 py-1.5 text-xs font-medium border rounded-full transition-all duration-200 cursor-pointer text-slate-600 bg-slate-50 border-slate-200 hover:bg-slate-100 hover:text-slate-900"
        >
          ☁️ {copy.tagSelfHosted}
        </a>
      </div>

      <div class="grid gap-4">
        {
          entries.map((entry) => (
            <a
              href={`/blog/${entry.id}`}
              data-blog-card
              data-tags={entry.data.tags ? entry.data.tags.join(",") : ""}
              class="group rounded-2xl border border-slate-200 bg-white p-6 shadow-sm transition hover:-translate-y-0.5 hover:border-brand-border hover:shadow-lg"
            >
              <div class="flex flex-wrap items-center gap-3 text-sm text-slate-500">
                <span>{entry.data.category}</span>
                <span>·</span>
                <time datetime={entry.data.publishDate.toISOString()}>
                  {getFormattedDate(entry.data.publishDate)}
                </time>
              </div>
              <h2 class="mt-3 text-2xl font-bold text-slate-900 transition group-hover:text-brand-text">
                {entry.data.title}
              </h2>
              <p class="mt-3 text-base leading-7 text-slate-600">
                {entry.data.snippet}
              </p>
            </a>
          ))
        }
      </div>
    </main>
  </Container>
</Layout>

<script is:inline>
  (() => {
    const updateFilters = () => {
      const urlParams = new URLSearchParams(window.location.search);
      const tag = urlParams.get("tag");

      // 1. 更新按钮激活状态
      const buttons = document.querySelectorAll("[data-tag-btn]");
      const activeClasses = ["text-brand", "bg-brand/5", "border-brand-border/40", "font-semibold", "shadow-sm"];
      const inactiveClasses = ["text-slate-600", "bg-slate-50", "border-slate-200", "hover:bg-slate-100", "hover:text-slate-900"];

      buttons.forEach((btn) => {
        const btnTag = btn.getAttribute("data-tag-btn");
        const isActive = (!tag && btnTag === "all") || (tag && btnTag === tag);

        if (isActive) {
          btn.classList.remove(...inactiveClasses);
          btn.classList.add(...activeClasses);
        } else {
          btn.classList.remove(...activeClasses);
          btn.classList.add(...inactiveClasses);
        }
      });

      // 2. 隐藏或显示对应的文章卡片
      const cards = document.querySelectorAll("[data-blog-card]");
      cards.forEach((card) => {
        if (!tag) {
          card.classList.remove("hidden");
          return;
        }
        const cardTags = (card.getAttribute("data-tags") || "").split(",");
        if (cardTags.includes(tag)) {
          card.classList.remove("hidden");
        } else {
          card.classList.add("hidden");
        }
      });
    };

    updateFilters();
    window.addEventListener("popstate", updateFilters);
  })();
</script>