Bin
2025-12-17 bc6aa38242b0a7dea4b18bc90e2d78740436a58b
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
45
46
47
48
const sanityClient = require('@sanity/client');
const fs = require('hexo-fs');
require('dotenv').config()
 
const client = sanityClient({
  projectId: 'k7elabj6',
  dataset: 'production',
  useCdn: false,
  token: process.env.SANITY_TOKEN,
  apiVersion: '2024-01-01',
  perspective: "published"
});
 
hexo.extend.filter.register('after_init', async function(){
 
  const query = `*[_type == "alert" && !(_id in path('drafts.**'))][0]`;
  const alert = await client.fetch(query);
 
  if(alert.docsUrl) {
    const template = `
      <a href="${alert.docsUrl}" class="Alert">
        <span class="AlertContent">
          ${alert.docsBadge && `<span class="Badge">${alert.docsBadge}</span>`}
          <span class="AlertText">${alert.docsText}</span>
          <svg fill="currentColor" viewBox="0 0 14 12"><path fill-rule="evenodd" d="m8.792.119 4.866 5.654-4.866 5.654-.948-.816 3.627-4.213H.54v-1.25h10.93L7.844.934l.948-.815Z" clip-rule="evenodd"></path></svg>
        </span>
      </a>`
 
    fs.writeFile("themes/v2/layout/partials/alert.ejs", template, (err) => {
      console.log(err);
    });
  }
 
  if(alert.humanSignalDocsUrl) {
    const template = `
      <a href="${alert.humanSignalDocsUrl}" class="Alert">
        <span class="AlertContent">
          ${alert.humanSignalDocsBadge && `<span class="Badge">${alert.humanSignalDocsBadge}</span>`}
          <span class="AlertText">${alert.humanSignalDocsText}</span>
          <svg fill="currentColor" viewBox="0 0 14 12"><path fill-rule="evenodd" d="m8.792.119 4.866 5.654-4.866 5.654-.948-.816 3.627-4.213H.54v-1.25h10.93L7.844.934l.948-.815Z" clip-rule="evenodd"></path></svg>
        </span>
      </a>`
 
    fs.writeFile("themes/v2/layout/partials/alert-enterprise.ejs", template, (err) => {
      console.log(err);
    });
  }
});