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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@magicpages/ghost-typesense-core

v1.11.0

Published

Core functionality for Ghost-Typesense integration

Readme

@magicpages/ghost-typesense-core

Core functionality for Ghost-Typesense integration. This package provides the essential services for indexing Ghost CMS content in Typesense.

Features

  • 🔄 Seamless synchronization between Ghost CMS and Typesense
  • 🔍 Automatic content transformation and indexing
  • ⚙️ Flexible configuration for custom fields and schema
  • 🚀 Efficient pagination handling for large Ghost sites
  • 🧩 TypeScript interfaces for type safety
  • 📝 Automatic plaintext generation from HTML content to make sure the most relevant content is indexed

Installation

npm install @magicpages/ghost-typesense-core

Usage

The core package provides the GhostTypesenseManager class which handles all interactions between Ghost and Typesense.

import { GhostTypesenseManager } from '@magicpages/ghost-typesense-core';
import { config } from './config';

async function main() {
  // Initialize the manager with your configuration
  const manager = new GhostTypesenseManager(config);
  
  // Create or recreate the Typesense collection with proper schema
  await manager.initializeCollection();
  
  // Index all posts from Ghost to Typesense
  await manager.indexAllPosts();
  
  // You can also index or delete individual posts
  await manager.indexPost('post-id');
  await manager.deletePost('post-id');
}

main().catch(console.error);

Configuration

This package requires a configuration object that follows the schema defined in @magicpages/ghost-typesense-config. The minimal configuration includes:

const config = {
  ghost: {
    url: 'https://your-ghost-blog.com',
    key: 'your-content-api-key'
  },
  typesense: {
    nodes: [{
      host: 'your-typesense-host',
      port: 443,
      protocol: 'https'
    }],
    apiKey: 'your-admin-api-key',
    connectionTimeoutSeconds: 10,
    retryIntervalSeconds: 0.1
  },
  collection: {
    name: 'ghost',
    fields: [
      { name: 'id', type: 'string', index: true },
      { name: 'title', type: 'string', index: true, sort: true },
      { name: 'slug', type: 'string', index: true },
      { name: 'html', type: 'string', index: true },
      { name: 'plaintext', type: 'string', index: true },
      { name: 'excerpt', type: 'string', index: true },
      { name: 'feature_image', type: 'string', index: false, optional: true },
      { name: 'published_at', type: 'int64', sort: true },
      { name: 'updated_at', type: 'int64', sort: true },
      { name: 'tags', type: 'string[]', facet: true, optional: true },
      { name: 'authors', type: 'string[]', facet: true, optional: true }
    ]
  }
};

API Reference

GhostTypesenseManager

The main class for managing Ghost content in Typesense.

Constructor

constructor(config: Config)

Creates a new instance with the provided configuration.

Methods

  • async initializeCollection(): Promise<void>
    Creates or recreates the Typesense collection with the schema defined in the configuration.

  • async indexAllPosts(): Promise<void>
    Fetches all posts from Ghost and indexes them in Typesense. Handles pagination automatically.

  • async indexPost(postId: string): Promise<void>
    Fetches a specific post from Ghost and indexes it in Typesense.

  • async deletePost(postId: string): Promise<void>
    Deletes a post from the Typesense collection.

  • async clearCollection(): Promise<void>
    Removes all documents from the collection and recreates it with the same schema.

Content Transformation

The package automatically handles content transformation from Ghost to Typesense, including:

  • Converting timestamps to numeric formats for sorting
  • Extracting tags and authors as arrays
  • Generating plaintext content from HTML for improved search relevance
  • Ensuring all required fields are properly formatted

Plaintext Generation

The plaintext generation process is particularly important for search quality:

  • Removes script tags and their content to eliminate JavaScript
  • Removes style tags and their content to eliminate CSS
  • Replaces all HTML tags with spaces to preserve word boundaries
  • Replaces HTML entities with spaces
  • Normalizes whitespace by collapsing multiple spaces to single spaces
  • Trims leading and trailing whitespace

Manual search tests have shown that this approach is more accurate than using the HTML content alone or Ghost's default plaintext field.

Related Packages

License

MIT