npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

siyuan_api_cache_lib

v1.0.7

Published

为思源挂件块提供 api 访问的工具库,同时具有缓存 api 调用结果到块属性上以及在非思源笔记环境下使用缓存结果的功能

Downloads

4

Readme

siyuan_api_cache_lib

为思源挂件块提供 api 访问的工具库,同时具有缓存 api 调用结果到块属性上以及在非思源笔记环境下使用缓存结果的功能

type-preview

目前提供的接口

  • api
    • sqlQuery : 对 post /api/query/sql 接口的包装
    • setBlockAttrs : 对 /api/attr/setBlockAttrs 接口的包装
    • getBlockAttrs : 对 /api/attr/getBlockAttrs 接口的包装
    • getBlockAttr : 对 /api/attr/getBlockAttrs 接口的包装,查询单个属性

查询类的 api 默认会进行缓存,非查询类的 api 则不会,可以通过查看函数的 noCache 属性来分辨,这个属性也是可以 set 的 (查询类的 api 也需要使用者自行斟酌避免过多的数据被缓存到挂件块的自定义属性)

  • util
    • htmlDecode : 思源对于 setBlockAttrs 的属性会 encode ,所以提供此工具方法
    • currentNodeId : 获取当前挂件块的 id
    • getCurrentEnv : 获取当前所处环境,例如 思源 与 OceanPress
  • config
    • server : @defaultValue "" 会在 api 请求路径的前面加上这个字段的值,便于开发调试
    • apiCache : @defaultValue true 对 api 上方法的调用是否开启缓存,如果需要支持 OceanPress 请开启此选项
    • maxCacheValueLength : @defaultValue 10 * 1024 缓存结果的最大长度,超出此长度则不会缓存且在控制台打印警告

注意事项

请确保使用了缓存的接口不会一直增长数据,否则容易出现如下问题

思源挂件块开发实践

由于本库使用了 self.frameElementframeElement 只能在同源的情况下才能访问到, 所以我在开发的时候使用 nginx 进行转发来绕过这个问题 (和跨域无关,我使用 chrome 关闭跨域的安全策略还是无法在非同源的情况下拿到 frameElement)

配置 iframe 的资源链接为 http://127.0.0.1/widgets/run-code/ (run-code 是我在开发的插件 github.com/run-code,建议查看这个项目里面对本库的使用方式)

对于在思源中的开发调试建议采用 nginx 进行如下配置,然后使用思源的在浏览器中打开,在这里进行开发调试

server {
    listen 80;
    server_name localhost 127.0.0.1;

    location / {
        #// 思源服务
        proxy_pass http://127.0.0.1:6806;
        proxy_set_header Host $host;
        index index.html index.htm;
    }
    location /widgets/run-code/ {
        #// run-code 所启动的服务, run-code 还配置了 base 路径为 /widgets/run-code/
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        index index.html index.htm;
    }
}

对于 OceanPress 的调试可以采用如下配置

server {
    listen 80;
    server_name localhost 127.0.0.1;

    location / {
        #// oceanPress 生成的静态站点目录
        alias 'D:/TEMP/思源test/';
    }
    location /widgets/run-code/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        index index.html index.htm;
    }
}