前言

创建服务

Untitled

Untitled

Untitled

克隆并修改代码

name = "blog" #你cloudflare的worker名称,也就是test-blog
main = "src/index.js"
compatibility_date = "2023-01-25"
route = "blog.kali-team.cn/*" #这个是你博客子域名
usage_model = "bundled"
env = { }

[triggers]
crons = [ ]

[vars]
MY_DOMAIN = "blog.kali-team.cn"
NOTION_DOMAIN = "kali-team.notion.site" #你分享出来的notion子域名
INDEX_PAGE_ID = "edb6a939baab4424a25fd295b3c51312" # 分享出来的主页page id
LINK_PAGE_ID = "9c74faba0b14441a93c2f94a40da3f79" # 友情链接页面的page id
DONATE_PAGE_ID = "eb55bc48f7fb42bfaef8473d2b7b63aa" # 赞助页面 page id
PAGE_TITLE = "Kali-Team" # 博客标题
PAGE_DESCRIPTION = "三米前有蕉皮" # 博客meta标签描述
SITEMAP_BODY = '{"source":{"type":"collection","id":"52de4e5e-ba6e-46a2-9dc5-5581637cf339","spaceId":"d4aa424b-d5f8-4dc3-a0fb-e5270f17203e"},"collectionView":{"id":"a5b688dd-2876-4f80-a47d-d84e713ac56e","spaceId":"d4aa424b-d5f8-4dc3-a0fb-e5270f17203e"},"loader":{"type":"reducer","reducers":{"collection_group_results":{"type":"results","limit":50},"table:uncategorized:title:unique":{"type":"aggregation","aggregation":{"property":"title","aggregator":"unique"}},"table:uncategorized:|oXv:latest_date":{"type":"aggregation","aggregation":{"property":"|oXv","aggregator":"latest_date"}},"table:uncategorized:L:TS:[object Object]":{"type":"aggregation","aggregation":{"property":"L:TS","aggregator":{"operator":"percent_per_group","groupName":"Complete"}}}},"sort":[{"property":"|oXv","direction":"descending"}],"searchQuery":"","userTimeZone":"Asia/Shanghai"}}'

Untitled

部署更新

➜  blog git:(main) wrangler2 publish
 ⛅️ wrangler 2.8.0 (update available 2.9.1)
-----------------------------------------------------
Your worker has access to the following bindings:
- Vars:
  - MY_DOMAIN: "blog.kali-team.cn"
  - NOTION_DOMAIN: "kali-team.notion.site"
  - INDEX_PAGE_ID: "edb6a939baab4424a25fd295b3c51312"
  - LINK_PAGE_ID: "9c74faba0b14441a93c2f94a40da3f79"
  - DONATE_PAGE_ID: "eb55bc48f7fb42bfaef8473d2b7b63aa"
  - PAGE_TITLE: "Kali-Team"
  - PAGE_DESCRIPTION: "三米前有蕉皮"
  - SITEMAP_BODY: "{"source":{"type":"collection","id":"..."
Total Upload: 19.32 KiB / gzip: 4.83 KiB
Uploaded blog (1.67 sec)
Published blog (3.85 sec)
  blog.kali-team.cn/*
Current Deployment ID: 4269accc-d181-4c21-992e-223d29426ea0

部署方式

安装Wrangler

npm install -g wrangler

登录Wrangler

wrangler login

初始化项目

wrangler init --from-dash blog
name = "blog"
main = "src/index.js"
compatibility_date = "2023-01-25"
route = "blog.kali-team.cn/*"
usage_model = "bundled"
env = { }

[triggers]
crons = [ ]

本地测试

wrangler dev
[b] open a browser, [d] open Devtools, [l] turn on local mode, [c] clear console, [x] to exit

发布项目

wrangler publish

搜索文章

      div.notion-topbar > div > div:nth-child(3) { display: none !important; }
-     div.notion-topbar > div > div:nth-child(4) { display: none !important; }
+     // div.notion-topbar > div > div:nth-child(4) { display: none !important; }
      div.notion-topbar > div > div:nth-child(5) { display: none !important; }
      div.notion-topbar > div > div:nth-child(6) { display: none !important; }
      div.notion-topbar-mobile > div:nth-child(3) { display: none !important; }
      div.notion-topbar-mobile > div:nth-child(4) { display: none !important; }
      div.notion-topbar > div > div:nth-child(1n).toggle-mode { display: block !important; }
      div.notion-topbar-mobile > div:nth-child(1n).toggle-mode { display: block !important; }

截图 2023-02-05 23.24.10.png

夜间模式

localStorage.__console = true;

sitemap.xml文件和订阅文件

response = await fetch(
    "https://" + NOTION_DOMAIN + "/api/v3/queryCollection?src=reset",
    {
      headers: {
        "User-Agent":
          "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0",
        Accept: "application/x-ndjson",
        "Accept-Language":
          "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
        "notion-client-version": "23.11.0.40",
        "notion-audit-log-platform": "web",
        "x-notion-active-user-header": "",
        "Content-Type": "application/json",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        Pragma: "no-cache",
        "Cache-Control": "no-cache",
      },
      body: SITEMAP_BODY,
      method: "POST",
    }
  );
<https://blog.kali-team.cn/notion-533c178345454e84a818fa72907e0d72>
原来的标题 处理后的URL
notion博客优化记录 notion-533c178345454e84a818fa72907e0d72#e722dd2fe103452cad19c3dc4222f1d7
Gather xshell and xftp passwords Gather-xshell-and-xftp-passwords-13785f54441e4b4791acc0f3fad32bf4
编写Metasploit插件获取DBeaver密码 Metasploit-DBeaver-9f42e26241c94ba785dce5f1e69697aa
Metasploit之插件-钉钉上线通知 Metasploit-35b456719f3f414e8a896bfd082c7a97
let original_page_title = page_title;
page_title = page_title.replace(/^[^-\\w.]{1,}/gmu, ""); //删除前面的
page_title = page_title.replace(/[^-\\w.]{1,}$/gmu, ""); //删除后面的
page_title = page_title.replace(/[^-\\w.]{1,}/gmu, "-"); //替换中间的
page_title = page_title.replace("--", ""); //替换双重横杠

浮动目录

// Notion 浮动 TOC
function TOC() {
  waitFor('.notion-table_of_contents-block').then(([el]) => {
    const toc = document.querySelector('.notion-table_of_contents-block');
    if (toc) {
        const toc_p = toc.parentElement;
        if (!toc_p.classList.contains('notion-column-block')) {
            return;
        }
        toc_p.style.position = 'sticky';
        toc_p.style.top = '0';
        toc_p.style.overflowY = 'scroll';
        toc_p.style.maxHeight = '50vh';
    }
});
}

页面布局

Untitled

Untitled

赞助页面

博客优化

CDN缓存

Untitled

Untitled

(http.host eq "blog.kali-team.cn" and (ends_with(http.request.uri.path, ".js") or (http.request.uri.path contains "/images/")))

Untitled

拦截无关请求

const HTTP_BLACK_LIST = {
  "<https://exp.notion.so/>": "",
  "<https://http-inputs-notion.splunkcloud.com/>": "",
  "<https://msgstore.www.notion.so/>": "",
  "<https://o324374.ingest.sentry.io/>": "",
  "/api/v3/trackSegmentEvent": "{}",
  "/api/v3/ping":"{}",
  // "/api/v3/getPublicPageData":"{\\"publicAccessRole\\":\\"none\\"}",
  "/api/v3/getUserAnalyticsSettings":
    '{"isIntercomEnabled":true,"isZendeskEnabled":true,"isAmplitudeEnabled":true,"isSegmentEnabled":true,"intercomAppId":"gpfdrxfd","noIntercomUserId":false,"isSprigEnabled":true,"isLoaded":true}',
};

const HTTP_BLACK_LIST = ${JSON.stringify(this.HTTP_BLACK_LIST)};
      async function HttpRewriter(resource, config){
        for (const [k,v] of Object.entries(HTTP_BLACK_LIST)) {
          if (resource.startsWith(k)){
            var init = { "status" : 200 , "statusText" : "OK" };
            var defaultResponse = new Response(null, init);
            if (v !=""){
              defaultResponse = new Response.json(JSON.stringify(v));
            }
            return defaultResponse;
          }
        }
        // console.log(resource,config)
        const response = await originalFetch(resource, config);
        return response;      
      }
      const { fetch: originalFetch } = window;
      window.fetch = async (...args) => {
          let [resource, config ] = args;
          const response = await HttpRewriter(resource, config);
          return response;
      };
response = new Response(
      body
        .replace(/'${MY_DOMAIN}'/g, NOTION_DOMAIN)
        .replace(/'${MY_DOMAIN}'/g, NOTION_DOMAIN)
+        .replace(/o324374.ingest.sentry.io/g, ''),
      response
    );

使用Rust WebAssembly重构博客

➜  ~ npx wrangler generate notion-blog-rs <https://github.com/cloudflare/workers-sdk/templates/experimental/worker-rust>
➜  ~ cd notion-blog-rs
➜  ~ npx wrangler dev
async fn main(mut req: Request, env: Env, _ctx: Context) -> Result<Response> {
    let my_domain = env.var("MY_DOMAIN")?.to_string();
    let notion_domain = env.var("NOTION_DOMAIN")?.to_string();
    let index = env.var("INDEX_PAGE_ID")?.to_string();
    let links = env.var("LINK_PAGE_ID")?.to_string();
    let donate = env.var("DONATE_PAGE_ID")?.to_string();
    // let title = env.var("DONATE_PAGE_ID")?.to_string();
    // let des = env.var("PAGE_DESCRIPTION")?.to_string();
    match req.path().as_str() {
        "/" => {
            return Response::redirect(format!("https://{}/{}", &my_domain, &index).parse()?);
        }
        "/links" => {
            return Response::redirect(format!("https://{}/{}", &my_domain, &links).parse()?);
        }
        "/donate" => {
            return Response::redirect(format!("https://{}/{}", &my_domain, &donate).parse()?);
        }
        _ => {}
    }
}
if matches!(req.method(), Method::Options) {
        let response = Response::empty()?;
        let mut header = Headers::new();
        header.set("Access-Control-Allow-Origin", "*")?;
        header.set(
            "Access-Control-Allow-Methods",
            "GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS",
        )?;
        header.set("Access-Control-Allow-Headers", "Content-Type")?;
        header.set("Access-Control-Allow-Credentials", "True")?;
        header.set("Access-Control-Max-Age", "1728000")?;
        return Ok(response.with_headers(header));
    }

使用lol-html重写页面

let mut rewriter = HtmlRewriter::new(
        Settings {
            element_content_handlers: vec![
                element!("body", |el| {
                    el.append(&h, ContentType::Html);
                    Ok(())
                }),
                element!("head", |el| {
                    el.append(head, ContentType::Html);
                    Ok(())
                }),
            ],
            ..Settings::default()
        },
        |c: &[u8]| output.extend_from_slice(c),
    );
    rewriter.write(&html).unwrap();
    rewriter.end().unwrap();

加载giscus评论

  1. 该仓库是公开的,否则访客将无法查看 discussion。
  2. giscus app 已安装,否则访客将无法评论和回应。
  3. Discussions 功能已在你的仓库中启用
<script
        src="<https://giscus.app/client.js>"
        data-repo="cn-kali-team/notion-blog"
        data-repo-id="R_kgDOI1wUgQ"
        data-category="Announcements"
        data-category-id="DIC_kwDOI1wUgc4CZK9O"
        data-mapping="pathname"
        data-strict="0"
        data-reactions-enabled="1"
        data-emit-metadata="0"
        data-input-position="top"
        data-theme="preferred_color_scheme"
        data-lang="zh-CN"
        data-loading="lazy"
        crossorigin="anonymous"
        async>
    </script>

配置CSP和动态加载

Powered by Kali-Team