Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor types & support warehouse6 #5483

Merged
merged 18 commits into from
Jan 22, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refator: refactor types
D-Sketon committed Apr 30, 2024
commit 5d0ae1324da72dfce5e3d5197e4bbe664e67dc4f
6 changes: 4 additions & 2 deletions lib/plugins/console/list/category.ts
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@ import { underline } from 'picocolors';
import table from 'text-table';
import { stringLength } from './common';
import type Hexo from '../../../hexo';
import type { CategorySchema } from '../../../types';
import type Model from 'warehouse/dist/model';

function listCategory(this: Hexo): void {
const categories = this.model('Category');
const categories: Model<CategorySchema> = this.model('Category');

const data = categories.sort({name: 1}).map(cate => [cate.name, String(cate.length)]);
const data = categories.sort({name: 1}).map((cate: CategorySchema) => [cate.name, String(cate.length)]);

// Table header
const header = ['Name', 'Posts'].map(str => underline(str));
6 changes: 4 additions & 2 deletions lib/plugins/console/list/page.ts
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@ import { magenta, underline, gray } from 'picocolors';
import table from 'text-table';
import { stringLength } from './common';
import type Hexo from '../../../hexo';
import type { PageSchema } from '../../../types';
import type Model from 'warehouse/dist/model';

function listPage(this: Hexo): void {
const Page = this.model('Page');
const Page: Model<PageSchema> = this.model('Page');

const data = Page.sort({date: 1}).map(page => {
const data = Page.sort({date: 1}).map((page: PageSchema) => {
const date = page.date.format('YYYY-MM-DD');
return [gray(date), page.title, magenta(page.source)];
});
6 changes: 4 additions & 2 deletions lib/plugins/console/list/post.ts
Original file line number Diff line number Diff line change
@@ -2,15 +2,17 @@ import { gray, magenta, underline } from 'picocolors';
import table from 'text-table';
import { stringLength } from './common';
import type Hexo from '../../../hexo';
import type { PostSchema } from '../../../types';
import type Model from 'warehouse/dist/model';

function mapName(item) {
return item.name;
}

function listPost(this: Hexo): void {
const Post = this.model('Post');
const Post: Model<PostSchema> = this.model('Post');

const data = Post.sort({published: -1, date: 1}).map(post => {
const data = Post.sort({published: -1, date: 1}).map((post: PostSchema) => {
const date = post.published ? post.date.format('YYYY-MM-DD') : 'Draft';
const tags = post.tags.map(mapName);
const categories = post.categories.map(mapName);
8 changes: 4 additions & 4 deletions lib/plugins/console/list/route.ts
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@ function listRoute(this: Hexo): void {
console.log(s);
}

function buildTree(routes) {
const obj = {};
let cursor;
function buildTree(routes: string[]) {
const obj: Record<string, any> = {};
let cursor: typeof obj;

for (let i = 0, len = routes.length; i < len; i++) {
const item = routes[i].split('/');
@@ -32,7 +32,7 @@ function buildTree(routes) {
return obj;
}

function buildNodes(tree) {
function buildNodes(tree: Record<string, any>) {
const nodes = [];

for (const [key, item] of Object.entries(tree)) {
6 changes: 4 additions & 2 deletions lib/plugins/console/list/tag.ts
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@ import { magenta, underline } from 'picocolors';
import table from 'text-table';
import { stringLength } from './common';
import type Hexo from '../../../hexo';
import type { TagSchema } from '../../../types';
import type Model from 'warehouse/dist/model';

function listTag(this: Hexo): void {
const Tag = this.model('Tag');
const Tag: Model<TagSchema> = this.model('Tag');

const data = Tag.sort({name: 1}).map(tag => [tag.name, String(tag.length), magenta(tag.path)]);
const data = Tag.sort({name: 1}).map((tag: TagSchema) => [tag.name, String(tag.length), magenta(tag.path)]);

// Table header
const header = ['Name', 'Posts', 'Path'].map(str => underline(str));
2 changes: 2 additions & 0 deletions test/scripts/hexo/hexo.ts
Original file line number Diff line number Diff line change
@@ -168,6 +168,7 @@ describe('Hexo', () => {
themeConfig.a.b.should.eql(3);

const Locals = hexo._generateLocals();
// @ts-expect-error
const { theme: themeLocals } = new Locals('', {path: '', layout: [], data: {}});

themeLocals.a.should.have.own.property('c');
@@ -187,6 +188,7 @@ describe('Hexo', () => {
themeConfig.c.should.eql(3);

const Locals = hexo._generateLocals();
// @ts-expect-error
const { theme: themeLocals } = new Locals('', {path: '', layout: [], data: {}});

themeLocals.should.have.own.property('c');

Unchanged files with check annotations Beta

return node;
}
run(context, args, body, callback) {

Check warning on line 62 in lib/extend/tag.ts

GitHub Actions / linter

'body' is defined but never used

Check warning on line 62 in lib/extend/tag.ts

GitHub Actions / linter

'callback' is defined but never used
return this._run(context, args, '');
}
return new nodes.CallExtension(this, 'run', node, [body]);
}
_parseBody(parser, nodes, lexer) {

Check warning on line 83 in lib/extend/tag.ts

GitHub Actions / linter

'nodes' is defined but never used

Check warning on line 83 in lib/extend/tag.ts

GitHub Actions / linter

'lexer' is defined but never used
const body = parser.parseUntilBlocks(`end${this.tags[0]}`);
parser.advanceAfterBlockEnd();
return body;
}
run(context, args, body, callback) {

Check warning on line 90 in lib/extend/tag.ts

GitHub Actions / linter

'callback' is defined but never used
return this._run(context, args, trimBody(body));
}
}
import type Document from 'warehouse/dist/document';
import type { CacheSchema } from '../types';
export = (ctx: Hexo) => {

Check warning on line 9 in lib/models/cache.ts

GitHub Actions / linter

'ctx' is defined but never used
const Cache = new warehouse.Schema({
_id: {type: String, required: true},
hash: {type: String, default: ''},
import warehouse from 'warehouse';
import type Hexo from '../hexo';
export = (ctx: Hexo) => {

Check warning on line 4 in lib/models/data.ts

GitHub Actions / linter

'ctx' is defined but never used
const Data = new warehouse.Schema({
_id: {type: String, required: true},
data: Object
import warehouse from 'warehouse';
import type Hexo from '../hexo';
export = (ctx: Hexo) => {

Check warning on line 4 in lib/models/post_category.ts

GitHub Actions / linter

'ctx' is defined but never used
const PostCategory = new warehouse.Schema({
post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'},
category_id: {type: warehouse.Schema.Types.CUID, ref: 'Category'}
import warehouse from 'warehouse';
import type Hexo from '../hexo';
export = (ctx: Hexo) => {

Check warning on line 4 in lib/models/post_tag.ts

GitHub Actions / linter

'ctx' is defined but never used
const PostTag = new warehouse.Schema({
post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'},
tag_id: {type: warehouse.Schema.Types.CUID, ref: 'Tag'}
return value;
}
match(value, query, data?) {

Check warning on line 45 in lib/models/types/moment.ts

GitHub Actions / linter

'data' is defined but never used
return value ? value.valueOf() === query.valueOf() : false;
}