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

hexo-ai-abstract

v1.2.0

Published

A Hexo plugin to generate AI-based abstracts for your blog posts. Fix hexo-ai-excerpt.

Downloads

407

Readme

A Hexo plugin to generate AI-based abstracts for your blog posts. Fix hexo-ai-excerpt.

CI status NPM version NPM downloads license

Features

  • [x] Core Functionality: AI Abstract Generation (using OpenAI API)
  • [x] Ignore Files via Tags
  • [x] Ignore Files via Title
  • [x] Ignore Files via Attribute
  • [x] Content Injection

Installation

npm install hexo-ai-abstract

How to use

Put hexo_ai_abstract config in your hexo/_config.yml.

hexo_ai_abstract:
  enable: 'on' # ['auto', 'on', 'off']
  apiKey: 'your-api-keys here'
  apiUrl: 'https://api.openai.com/v1'
  model: 'gpt-4o-mini'
  prompt: 'You are a highly skilled AI trained in language comprehension and summarization. I would like you to read the text delimited by triple quotes and summarize it into a concise abstract paragraph. Aim to retain the most important points, providing a coherent and readable summary that could help a person understand the main points of the discussion without needing to read the entire text. Please avoid unnecessary details or tangential points. Only give me the output and nothing else. Do not wrap responses in quotes. Respond in the Chinese language.'
  ignoreEl: [
    'table', 'pre', 'figure'
  ]
  ignores:
    byTitle: [ '{{title}}' ]
    byTag: [ 'about', 'encrypt' ]
    byAttribute: ['password']
  inject: 
    anchor: '<!-- more -->'
    front: True 
  maxTokens: 5000

This plugin will upload data.content to the AI service to generate an abstract when you save a post without excerpt Front-Matter. The abstract will then be used to construct the excerpt.

The generated abstract will look like this:

---
title: Your Post Title
tags:
  - notencrypt
aiabstract: >-
  Generated Abstract.
---

1. Test your _config.yml

You can set "enable" to "on" to test whether the plugin is functioning.

hexo_ai_abstract:
  enable: 'on'

When "enable" is set to either "on" or "auto," the visualization results of the decision tree are as follows.

  graph TD;
      A(aiAbstract)-->B1(defined);
      A-->B2(undefined);
      
      B1-->C1(not null);
      B1-->C2(null);

      C1-->Z1;
      C2-->Z0;

      B2-->D1(enable is 'auto');
      B2-->D2(enable is 'on');

      D1-->Z0;
      D2-->Z2;

      Z0(Generate aiAbstract);
      style Z0 color:#33aa33
      Z1(Already exists, not Generate);
      style Z1 color:#aa3333
      Z2(Not Generate);
      style Z2 color:#aa3333

Specifically, when "enable" is set to "on," the AI summary generation will only be executed if the aiAbstract attribute of the post exists and is empty. Consequently, you can test the plugin's availability by adding the aiAbstract attribute to a post and leaving it empty.

2. Ignores

For some personal post, e.g. encrypted posts, uploading the post's content might be undesirable. To address this, hexo-ai-abstract offers features to "Ignore Files via Tags", "Ignore Files via Title" and "Ignore Files via Attribute".

Ignore Files via Tags

You can filter out posts that you don't want to process by tagging them accordingly. For example:

title: Post Title
tags:
  - secret

Then, in your _config.yml, you can specify the tags to ignore:

hexo_ai_abstract:
  ignores:
    byTag: [ 'secret', '...' ]

Any post tagged with a tag listed in ignoreTag will be skipped during the abstract generation process.

Ignore Files via Title

Some plugins and software may include post templates. However, generating summaries from the content of these templates is generally undesirable.

To address this, the option to "Ignore Files via Title" has been introduced. For example, using the "insect template" in Obsidian, if the post title is set to {{title}}:

---
title: '{{title}}'
toc: true
recommend: 1
keywords: '{{title}}'
uniqueId: '{{date}} {{time}}/{{title}}.html'
...

You can specify in the _config.yml to ignore posts with the title "{{title}}":

hexo_ai_abstract:
  ignores:
    byTitle: [ '{{title}}' ]

After that, the plugin will not generate AI abstract for these posts.

Ignore Files via Attribute

In the plugin hexo-blog-encrypt, you can encrypt posts not only by using tags but also by adding a password in the post attributes. Therefore, we have also incorporated the corresponding functionality.

For example, if a password is added to a post:

---
...
comments: false
password: pa33w@rd
...

You should also specify the password in the _config.yml:

hexo_ai_abstract:
  ignores:
    byAttribute: [ 'password' ]

Subsequently, the plugin will ignore this post.

3. Content Injection

In our initial version, the generated AI summaries were stored in the excerpt attribute. However, if there is content in the excerpt, the content before the <!-- more --> will not be displayed as an excerpt on the homepage, and the excerpt content cannot be rendered within the main body.

To address this issue, the hexo-ai-abstract plugin has implemented the following changes after v1.1.0:

  • The generated AI abstract is now stored in the aiAbstract attribute.
  • An injection feature has been added: the content from aiAbstract is injected into the main content.

This functionality requires you to add configuration settings in the _config.yml:

hexo_ai_abstract:
  inject:
    anchor: '<!-- more -->'
    front: False

The plugin will first match the content in inject.anchor and then determine whether to inject the AI summary content before or after inject.anchor based on the inject.front setting.

Taking anchor: '<!-- more -->' as an example, if front: True, the AI summary will be generated before the <!-- more --> tag. Conversely, if front: False, the AI summary will be generated after the <!-- more --> tag.

Acknowledgement

We sincerely thank hexo-ai-excerpt and hexo-ai-summaries for their pioneering work, which served as an inspiration for the creation of hexo-ai-abstract.

Licence

hexo-ai-abstract is released under the MIT License. You are free to use, modify, and distribute this software under the terms of the MIT License. We encourage contributions and feedback to help improve the project.