Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Jan 19, 2024
1 parent ce3229c commit 6a03824
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/plugins/generator/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@ import { exists, createReadStream } from 'hexo-fs';
import Promise from 'bluebird';
import { extname } from 'path';
import { magenta } from 'picocolors';
import type warehouse from 'warehouse';
import type Hexo from '../../hexo';
import type { AssetGenerator } from '../../types';
import type { AssetGenerator, AssetSchema } from '../../types';
import type Document from 'warehouse/dist/document';

interface Data {
modified: boolean;
data?: () => any;
}

const process = (name: string, ctx: Hexo) => {
// @ts-expect-error
return Promise.filter(ctx.model(name).toArray(), (asset: warehouse['Schema']) => exists(asset.source).tap(exist => {
// @ts-expect-error
return Promise.filter(ctx.model(name).toArray(), (asset: Document<AssetSchema>) => exists(asset.source).tap(exist => {
if (!exist) return asset.remove();
})).map((asset: warehouse['Schema']) => {
// @ts-expect-error
})).map((asset: Document<AssetSchema>) => {
const { source } = asset;
// @ts-expect-error
let { path } = asset;
const data: Data = {
// @ts-expect-error
modified: asset.modified
};

// @ts-expect-error
if (asset.renderable && ctx.render.isRenderable(path)) {
// Replace extension name if the asset is renderable
const filename = path.substring(0, path.length - extname(path).length);
Expand Down
9 changes: 9 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ export interface TagSchema {
_id?: string | number;
name?: string;
}

export interface AssetSchema {
_id?: string;
path: string;
modified: boolean;
renderable: boolean;
source: string;
}

export interface LocalsType {
page: PostSchema | PageSchema;
path: string;
Expand Down

0 comments on commit 6a03824

Please sign in to comment.