summaryrefslogtreecommitdiff
path: root/src/pages/blog/keywords/index.astro
blob: 1b3b62cc36cbb70321374ba233d3b5c03caf0fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
import { getCollection } from "astro:content";
import Base from "@layouts/Base.astro";
import KeywordsList from "@components/organisms/KeywordsList.astro";

const title = "Palavras-Chave";
const description = "Palavras-Chave";

const blogs = await getCollection("blog");

const map: Map<string, number> = new Map();
for (const { data } of blogs) {
  if (!("keywords" in data)) {
    continue;
  }

  for (const k of data.keywords) {
    const n = map.get(k) ?? 0;
    map.set(k, n + 1);
  }
}

let keywords = Array.from(map.entries()).sort(([, a], [, b]) => b - a);
---

<Base {title} {description} keywords={keywords.map(([x]) => x)}>
  <main
    itemprop="mainContentOfPage"
    itemscope
    itemtype="https://schema.org/WebPageElement"
  >
    <h2 itemprop="name description">Palavras-Chave</h2>
    <div>
      <KeywordsList {keywords} />
    </div>
  </main>
</Base>

<style>
  div {
    display: flex;
    margin-inline: auto;
  }
</style>