Artalk API Reference

website·Indexed 31 days ago

https://artalk.js.org/guide/intro.html

Type definitions and API documentation for Artalk, featuring interfaces for Context, Editor, UserManager, and ConfigManager, as well as configuration types like ArtalkConfig and ArtalkPlugin.

Tokens
76.7K
Snippets
518
Records
641
Agent score
65%

What's inside Artalk

  1. Overview of Artalk commenting system

    Artalk is a lightweight and feature-rich commenting system designed for effortless deployment and integration into blogs, websites, or web applications. It consists of a TypeScript (Vanilla JS) frontend (~40KB gzipped) and a cross-platform backend written in Golang (Artalk v2). It is compatible with various frontend frameworks including Vue, React, and Svelte, as well as CMS platforms like WordPress, Typecho, and Hexo.
  2. Overview of Artalk commenting system

    Artalk is a lightweight, feature-rich commenting system designed for effortless deployment and integration into blogs, websites, or web applications. It consists of a TypeScript (Vanilla JS) frontend (~40KB gzipped) and a cross-platform backend written in Golang (v2). It is compatible with various frontend frameworks including Vue, React, and Svelte, as well as CMS platforms like WordPress, Typecho, and Hexo.
  3. Initialize Artalk using the default class

    The default class is the primary entry point for Artalk. It is initialized via its constructor, which accepts configuration options (conf) and context (ctx) to set up the comment system. Once instantiated, the class provides methods to manage the Artalk lifecycle, including initialization, updating, and destroying the instance.
    // Example instantiation (based on constructor parameters)
    const artalk = new Artalk({
      conf: { /* configuration options */ },
      ctx: { /* context options */ }
    });
  4. Use ArtalkLite for a lightweight comment system

    ArtalkLite is a streamlined version of Artalk designed for smaller bundle sizes. Compared to the standard version, it has the following characteristics:

    • Emojis, voting, and User-Agent (UA) badges are disabled by default.
    • It removes the dependency on the marked library, though it still supports basic Markdown syntax.

    To use ArtalkLite via CDN, replace Artalk with ArtalkLite in the distribution file names.

    <!-- JS -->
    <script src="https://unpkg.com/artalk@2.10.0/dist/ArtalkLite.js"></script>
    <!-- CSS -->
    <link rel="stylesheet" href="https://unpkg.com/artalk@2.10.0/dist/ArtalkLite.css">
  5. Use ArtalkLite for a lightweight comment system

    ArtalkLite is a streamlined version of Artalk designed for smaller bundle sizes. Compared to the standard version, it has the following characteristics:

    • Emojis, voting, and User-Agent (UA) badges are disabled by default.
    • It removes the dependency on the marked library, though it still supports basic Markdown syntax.
    • It is released concurrently with the standard version.
  6. Use the SiteData interface for site information

    The SiteData interface is used to represent metadata about a site. It contains the site's unique identifier, name, and associated URLs.
    interface SiteData {
      first_url: string; // The primary URL of the site
      id: number;       // The unique site ID
      name: string;     // The name of the site
      urls: string[];   // A list of site URLs
      urls_raw: string; // The raw string representation of site URLs
    }
  7. Available variables for Artalk email templates

    When creating a custom HTML email template, you can use the following variables to dynamically populate user and comment data. The data includes details about the reply, the original comment, and the site context.
    <div>
      <p>Hi, {{nick}}:</p>
      <p>You have received a reply in “{{page_title}}”:</p>
      <div>
        <div>@{{reply_nick}}:</div>
        <div>{{reply_content}}</div>
      </div>
      <p><a href="{{link_to_reply}}" target="_blank">Reply to the message »</a></p>
    </div>
  8. Manage multiple sites in Artalk

    Artalk supports multi-site management. Administrators can create, manage, and switch between multiple sites and their respective comments and pages via the "Dashboard" located in the sidebar.
  9. Use the ApiVersionData interface for API version tracking

    The ApiVersionData interface defines the structure for storing metadata about the API program, including its name, the specific commit hash, and the version number.
    interface ApiVersionData {
      app: string;        // API program name
      commit_hash: string; // API program commit hash
      version: string;     // API program version number
    }
  10. Manage multiple sites in Artalk

    Artalk supports multi-site management, allowing administrators to create, manage, and switch between multiple sites and their respective comments and pages from a centralized interface located in the "Dashboard" accessible from the sidebar.
  11. CommentData interface reference

    The CommentData interface defines the structure of a comment object in Artalk. It contains details about the comment content, the author's identity, moderation status (pinned, pending, visible), and engagement metrics (votes).
    interface CommentData {
      badge_color?: string;    // Badge color
      badge_name?: string;     // Badge text
      content: string;         // Comment body
      date: string;            // Comment date
      email?: string;          // User email (Admin only)
      email_encrypted: string;  // Encrypted user email
      id: number;              // Comment ID
      ip_region?: string;      // IP region/location
      is_allow_reply: boolean;  // Whether replies are allowed
      is_collapsed: boolean;   // Whether the comment is collapsed
      is_pending: boolean;      // Whether the comment is pending review
      is_pinned: boolean;       // Whether the comment is pinned
      is_verified: boolean;    // Whether the user is verified
      link: string;            // User profile link
      nick: string;            // User nickname
      page_key: string;        // Page key where the comment was posted
      page_url?: string;       // URL of the page where the comment was posted
      rid: number;             // ID of the comment being replied to
      site_name: string;       // Site name (used for isolation)
      ua: string;              // User Agent
      visible: boolean;        // Whether the comment is visible
      vote_down: number;       // Number of downvotes
      vote_up: number;         // Number of upvotes
    }
  12. Reference Artalk email notification data schema

    The following JSON structure represents the data available for rendering email templates. It includes detailed information about the comment, the parent comment, the page, and the site.
    {
      "content": "<p>Test content</p>\n",
      "link_to_reply": "https://artalk.js.org/?atk_comment=8100&atk_notify_key=44a9b2f08312565fba47c716df9d177f",
      "nick": "Username",
      "page_title": "Artalk",
      "page_url": "https://artalk.js.org/",
      "reply_content": "<p>Replier's content</p>\n",
      "reply_nick": "Replier",
      "site_name": "ArtalkDemo",
      "site_url": "http://localhost:3000/",
      "comment.content": "<p>Replier's content</p>\n",
      "comment.content_raw": "Replier's content",
      "comment.date": "2021-11-22",
      "comment.id": 8100,
      "comment.nick": "Replier",
      "comment.page.title": "Artalk",
      "comment.page.url": "https://artalk.js.org/",
      "parent_comment.content": "<p>Test content</p>\n",
      "parent_comment.nick": "Username",
      "parent_comment.id": 8099
    }