Skip to content

Commit

Permalink
✨ feat: Update seo config
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Mar 24, 2024
1 parent f5b0855 commit 9ca366c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
2 changes: 2 additions & 0 deletions packages/lobe-seo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Some additional configurations are provided in this project, set using environme
| -------------- | -------- | -------------- | --------------- | -------------------------------- |
| entry | `*` | `string` | - | Entry file or folder |
| entryExtension | | `string` | `.mdx` | Entry file extension |
| groupKey | | `string` | - | Set group key for SEO matters |
| tagStringify | | `boolean` | `false` | Stringify the tags array |
| modelName | | `string` | `gpt-3.5-turbo` | Model used |
| temperature | | `number` | `0` | Sampling temperature used |
| experimental | | `experimental` | `{}` | Experimental features, see below |
Expand Down
16 changes: 9 additions & 7 deletions packages/lobe-seo/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ $ lobe-seo -c './custom-config.js' # or use the full flag --config

## 🔍 配置

| 属性名称 | 必填 | 类型 | 默认值 | 描述 |
| -------------- | ---- | -------------- | --------------- | ------------------ |
| entry | `*` | `string` | - | 入口文件或文件夹 |
| entryExtension | | `string` | `.mdx` | 入口文件扩展名 |
| modelName | | `string` | `gpt-3.5-turbo` | 使用的模型 |
| temperature | | `number` | `0` | 使用的采样温度 |
| experimental | | `experimental` | `{}` | 实验性功能,见下文 |
| 属性名称 | 必填 | 类型 | 默认值 | 描述 |
| -------------- | ---- | -------------- | --------------- | ---------------------------- |
| entry | `*` | `string` | - | 入口文件或文件夹 |
| entryExtension | | `string` | `.mdx` | 入口文件扩展名 |
| groupKey | | `string` | - | 为 Seo Matter 设置 Gorup key |
| tagStringify | | `boolean` | `false` | 将 tags 字符串化 |
| modelName | | `string` | `gpt-3.5-turbo` | 使用的模型 |
| temperature | | `number` | `0` | 使用的采样温度 |
| experimental | | `experimental` | `{}` | 实验性功能,见下文 |

#### `experimental`

Expand Down
1 change: 1 addition & 0 deletions packages/lobe-seo/examples/.seorc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
entry: ['./docs/**/*.mdx'],
modelName: 'gpt-3.5-turbo-1106',
groupKey: 'seo',
experimental: {
jsonMode: true,
},
Expand Down
8 changes: 7 additions & 1 deletion packages/lobe-seo/src/commands/Seo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ class Seo {
try {
const md = readMarkdown(file);
const { data, content } = matter(md);

if (data) {
const seo = (data as BlogPost)?.seo as PostSEO;
let seo: PostSEO;
seo = this.config.groupKey
? ((data as BlogPost)?.[this.config.groupKey] as PostSEO)
: (data as BlogPost);

if (seo && seo.tags && seo.title && seo.description) {
continue;
}
}

this.query.push({
content,
entry: file,
Expand Down
27 changes: 20 additions & 7 deletions packages/lobe-seo/src/core/SeoCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export interface SeoQueryItem {

export class SeoCore {
private seoService: SeoMdx;
private config: SeoConfig;
constructor({ openAIApiKey, openAIProxyUrl, config }: SeoOptions) {
this.config = config;
this.seoService = new SeoMdx(config, openAIApiKey, openAIProxyUrl);
}

Expand Down Expand Up @@ -51,13 +53,24 @@ export class SeoCore {
needToken,
});

const result = {
...matter,
seo: {
...seoResult,
...matter.seo,
},
};
let result: BlogPost;

if (this.config.tagStringify) {
seoResult.tags = seoResult.tags.join(', ');
}

result = this.config.groupKey
? {
...matter,
[this.config.groupKey]: {
...seoResult,
...matter?.[this.config.groupKey],
},
}
: {
...seoResult,
...matter,
};

return {
result,
Expand Down
7 changes: 3 additions & 4 deletions packages/lobe-seo/src/types/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export interface PostSEO {
title: string;
}

export interface BlogPost {
seo: PostSEO;
title: string;
}
export type BlogPost = PostSEO & {
[groupKey: string]: PostSEO;
};
14 changes: 14 additions & 0 deletions packages/lobe-seo/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@ export interface SeoConfig {
* @description Number of concurrently pending promises returned
*/
concurrency?: number;
/**
* @description Entry files path
*/
entry: string[];
/**
* @description The entry file or folder, support glob
*/
entryExtension: string;
/**
* @description Exclude files path
*/
exclude: string[];
experimental?: {
jsonMode?: boolean;
};
/**
* @description Set group key for SEO matters
*/
groupKey?: string;
/**
* @description ChatGPT model name to use
*/
modelName?: LanguageModel;
/**
* @description Stringify the tags array
*/
tagStringify?: boolean;
/**
* @description Sampling temperature to use
*/
Expand Down

0 comments on commit 9ca366c

Please sign in to comment.