Hyoban

Hyoban

Don’t do what you should do, do you want.
twitter
github
email
telegram

xLog SDK 的一些進展

Why do we need the xLog SDK?#

Although I am very satisfied with the overall experience of xLog, I have to say that compared to static generated sites like Hexo and VitePress, its loading speed is still a bit slow. Currently, we don't have a simple way to deploy xLog ourselves or generate static sites using xLog data.

xLog allows us to easily customize the appearance of our website using CSS, but when it comes to how the pages are rendered, the customization options are limited. In the article "How to Compile a Markdown Document Gracefully" by diygod, he explains how xLog renders Markdown. However, you may not be satisfied with the style of code highlighting or have a need to highlight specific lines. Sometimes, you can meet your needs by submitting a PR to xLog, but not all needs are suitable for every xLog user. If we can control how Markdown is rendered ourselves, we will have more freedom.

For many people, xLog is not their only platform for blogging, note-taking, or daily publishing. Some people are used to using VS Code to edit their blogs, while others prefer Obsidian. With an xLog SDK, when integrating with other platforms, community authors don't need to implement the logic of an xLog server for each person. This repetitive work should be unified through the SDK.

Current functionalities of the SDK#

I have released version 0.1.0 of sakuin, which you can install via npm:

npm install sakuin

Import Client from sakuin and use it, which is based on crossbell.js. Generally, you need to pass the handle to get data for a specific site, which is your xLog subdomain.

import { Client } from "sakuin"

const client = new Client()
const site = await client.site.getInfo(HANDLE)

You can perform the following operations:

  1. Get site information with client.site.getInfo
    1. Get site statistics with client.site.getStat
  2. Get blog information
    1. Get all blogs with client.post.getAll
    2. Get blogs in pagination with client.post.getMany
    3. Get a single blog with client.post.get or client.post.getBySlug
    4. Create a blog with client.post.put
    5. Update a blog with client.post.update
  3. Get comment information, send anonymous comments
  4. Get short and portfolio information

I cannot introduce all the available APIs and parameters here, but you can learn how to use them through TypeScript types, and I will also generate documentation later.

What can we do with the SDK?#

sakuin is derived from my blog project, so naturally, I use it to build my own blog. You can compare its loading speed with the original xLog. In addition, I have re-implemented the layout and rendering of articles according to my preferences, giving me complete control and freedom. By integrating with the anonymous comment interface provided by xLog, I can easily implement a comment module.

Screenshot of the comment interface

VS Code xLog plugin, with this plugin, you can download all blog articles to your local machine and edit or create your blog locally. You can also upload local files or remote linked files to IPFS in VS Code.

Some prospects#

Regarding the future of the xLog SDK, I can think of the following points:

  1. Further improve the APIs needed for third-party interaction with xLog and contact xLog community authors to provide a unified and convenient development experience for community authors.
  2. Fully implement the ability of an xLog server, transfer the project to the Crossbell organization, or even replace the current implementation of the xLog server.
  3. Provide server APIs for the SDK so that we can interact without using the SDK.

Regarding the idea of integrating xLog using the SDK:

  1. Integrate git commit hooks to automatically create and update blogs.

I believe that the emergence of the xLog SDK can make xLog more in line with the concept of decentralization, allowing more and more people to truly utilize their own data instead of just accessing it through platforms. BTW, this blog post was written in VS Code and published using the xLog plugin.

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。