vuepress-plugin-blog2
Advanced tools
Comparing version 2.0.0-alpha.11 to 2.0.0-alpha.12
@@ -1,1 +0,46 @@ | ||
export * from "./composables"; | ||
import * as vue from 'vue'; | ||
import { ComputedRef } from 'vue'; | ||
interface Article<T extends Record<string, unknown> = Record<string, unknown>> { | ||
path: string; | ||
meta: T; | ||
} | ||
declare type Articles<T extends Record<string, unknown> = Record<string, unknown>> = Article<T>[]; | ||
interface BlogCategoryData<T extends Record<string, unknown> = Record<string, unknown>> { | ||
path: string; | ||
map: Record<string, { | ||
path: string; | ||
items: Articles<T>; | ||
}>; | ||
} | ||
interface BlogTypeData<T extends Record<string, unknown> = Record<string, unknown>> { | ||
path: string; | ||
items: Articles<T>; | ||
} | ||
declare const blogCategoryMap: vue.Ref<{ | ||
[x: string]: { | ||
[x: string]: { | ||
path: string; | ||
map: { | ||
[x: string]: { | ||
path: string; | ||
keys: string[]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}>; | ||
declare const useBlogCategory: <T extends Record<string, unknown> = Record<string, unknown>>(key: string) => ComputedRef<BlogCategoryData<T>>; | ||
declare const blogTypeMap: vue.Ref<{ | ||
[x: string]: { | ||
[x: string]: { | ||
path: string; | ||
keys: string[]; | ||
}; | ||
}; | ||
}>; | ||
declare const useBlogType: <T extends Record<string, unknown> = Record<string, unknown>>(key: string) => ComputedRef<BlogTypeData<T>>; | ||
export { blogCategoryMap, blogTypeMap, useBlogCategory, useBlogType }; |
@@ -1,4 +0,168 @@ | ||
import { blogPlugin } from "./plugin"; | ||
export * from "./plugin"; | ||
export * from "../shared"; | ||
export default blogPlugin; | ||
import { Page, Plugin, PluginConfig } from '@vuepress/core'; | ||
import { BasePageFrontMatter } from '@mr-hope/vuepress-shared'; | ||
interface BlogCategoryFrontmatterOptions { | ||
type: "category"; | ||
key: string; | ||
name?: string; | ||
} | ||
interface BlogTypeFrontmatterOptions { | ||
type: "type"; | ||
key: string; | ||
} | ||
interface BlogPluginFrontmatter extends BasePageFrontMatter { | ||
blog: BlogCategoryFrontmatterOptions | BlogTypeFrontmatterOptions; | ||
} | ||
declare type PageMap = Record</** Locale Path */ string, /** Pages */ Page[]>; | ||
declare type ArticleMap = Record< | ||
/** Locale Path */ string, | ||
/** Page Keys */ string[]>; | ||
interface CategoryConfig { | ||
path: string; | ||
keys: string[]; | ||
} | ||
declare type CategoryLocaleMap = Record< | ||
/** Category name */ string, | ||
/** Category config */ CategoryConfig>; | ||
interface CategoryLocaleConfig { | ||
/** Main page of category */ | ||
path: string; | ||
/** category map for current locale */ | ||
map: CategoryLocaleMap; | ||
} | ||
declare type CategoryMap = Record< | ||
/** Locale Path */ string, | ||
/** Locale category config */ CategoryLocaleConfig>; | ||
interface TypeConfig { | ||
path: string; | ||
keys: string[]; | ||
} | ||
declare type TypeMap = Record< | ||
/** Locale Path */ string, | ||
/** Locale Type config */ TypeConfig>; | ||
interface BlogTypeOptions { | ||
/** | ||
* Unique type name | ||
*/ | ||
key: string; | ||
/** | ||
* A filter function to determine whether a page should be the type | ||
*/ | ||
filter: (page: Page) => boolean; | ||
/** | ||
* A custom function to sort the pages | ||
*/ | ||
sorter?: (pageA: Page, pageB: Page) => number; | ||
/** | ||
* Path to register | ||
* | ||
* @default '/:key/' | ||
*/ | ||
path?: string; | ||
/** | ||
* Layout name | ||
* | ||
* @default 'Layout' | ||
*/ | ||
layout?: string; | ||
} | ||
interface BlogCategoryOptoins { | ||
/** | ||
* Unique category name | ||
*/ | ||
key: string; | ||
/** | ||
* Function getting category | ||
*/ | ||
getter: (page: Page) => string[]; | ||
/** | ||
* A custom function to sort the pages | ||
*/ | ||
sorter?: (pageA: Page, pageB: Page) => number; | ||
/** | ||
* Path pattern or custom function | ||
* | ||
* @description when filling in a string, `:key` will be replaced by the "slugify" result of the orginal key and name | ||
* | ||
* @default `/:key/:name/` | ||
*/ | ||
path?: string; | ||
/** | ||
* Layout name | ||
* | ||
* @default 'Layout' | ||
*/ | ||
layout?: string; | ||
/** | ||
* Path pattern or custom function | ||
* | ||
* @description when filling in a string, `:key` and `:name` will be replaced by the "slugify" result of the orginal key and name | ||
* | ||
* @default `/:key/:name/` | ||
*/ | ||
itemPath?: string | ((name: string) => string); | ||
/** | ||
* Layout name | ||
* | ||
* @default 'Layout' | ||
*/ | ||
itemLayout?: string; | ||
} | ||
interface BlogOptions { | ||
/** | ||
* @default '_blog' | ||
*/ | ||
metaScope?: string; | ||
/** | ||
* Injecting meta | ||
* | ||
* 向路由中注入信息 | ||
*/ | ||
injectMeta?: (page: Page) => Record<string, unknown>; | ||
/** | ||
* Page filter, determine whether a page should be included | ||
* | ||
* 页面过滤器,此函数用于鉴别页面是否作为文章 | ||
* | ||
* @default () => true | ||
*/ | ||
filter?: (page: Page) => boolean; | ||
/** | ||
* Slugify function | ||
* | ||
* @default (name) => encodeURI(name.replace(/ _/g, '-')).toLowerCase() | ||
*/ | ||
slugify?: (name: string) => string; | ||
/** | ||
* Types | ||
*/ | ||
type?: BlogTypeOptions[]; | ||
/** | ||
* Categories | ||
*/ | ||
category?: BlogCategoryOptoins[]; | ||
} | ||
interface Article<T extends Record<string, unknown> = Record<string, unknown>> { | ||
path: string; | ||
meta: T; | ||
} | ||
declare type Articles<T extends Record<string, unknown> = Record<string, unknown>> = Article<T>[]; | ||
interface BlogCategoryData<T extends Record<string, unknown> = Record<string, unknown>> { | ||
path: string; | ||
map: Record<string, { | ||
path: string; | ||
items: Articles<T>; | ||
}>; | ||
} | ||
interface BlogTypeData<T extends Record<string, unknown> = Record<string, unknown>> { | ||
path: string; | ||
items: Articles<T>; | ||
} | ||
declare const blogPlugin: Plugin<BlogOptions>; | ||
declare const blog: (options: BlogOptions | false) => PluginConfig<BlogOptions>; | ||
export { Article, ArticleMap, Articles, BlogCategoryData, BlogCategoryFrontmatterOptions, BlogCategoryOptoins, BlogOptions, BlogPluginFrontmatter, BlogTypeData, BlogTypeFrontmatterOptions, BlogTypeOptions, CategoryConfig, CategoryLocaleConfig, CategoryLocaleMap, CategoryMap, PageMap, TypeConfig, TypeMap, blog, blogPlugin, blogPlugin as default }; |
@@ -1,8 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const plugin_1 = require("./plugin"); | ||
(0, tslib_1.__exportStar)(require("./plugin"), exports); | ||
(0, tslib_1.__exportStar)(require("../shared"), exports); | ||
exports.default = plugin_1.blogPlugin; | ||
//# sourceMappingURL=index.js.map | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@vuepress/core");const t=new(require("@mr-hope/vuepress-shared").Logger)("vuepress-plugin-blog2"),a=(e,t)=>{const{filter:a=(()=>!0)}=e,o={};return t.pages.filter(a).forEach((e=>{o[e.pathLocale]||(o[e.pathLocale]=[]),o[e.pathLocale].push(e)})),o},o=e=>e.replace(/^\//,""),r=(a,r,p)=>{const{category:n=[],slugify:s=(e=>e.replace(/[ _]/g,"-").toLowerCase())}=r;return Promise.all(n.map((async({key:r,getter:n,sorter:i=(()=>-1),path:c="/:key/",layout:l="Layout",itemPath:u="/:key/:name/",itemLayout:g="Layout"},y)=>{if("string"!=typeof r||!r)return t.error(`Invalid 'key' option ${r} in 'category[${y}]'`),null;if("function"!=typeof n)return t.error(`Invalid 'getter' option in 'category[${y}]', it should be a function!`),null;const h={},f=[],m="function"==typeof u?u:e=>u.replace(/:key/g,s(r)).replace(/:name/g,s(e));for(const t in p){const u=await e.createPage(a,{path:`${t}${o(c.replace(/:key/g,s(r)))}`,frontmatter:{blog:{type:"category",key:r},layout:l}});a.pages.push(u),f.push(u.path),h[t]={path:u.path,map:{}};const{map:y}=h[t],_={};for(const s of p[t]){const p=n(s);for(const n of p){if(!y[n]){const p=await e.createPage(a,{path:`${t}${o(m(n))}`,frontmatter:{blog:{type:"category",name:n,key:r},layout:g}});a.pages.push(p),f.push(p.path),y[n]={path:p.path,keys:[]},_[n]=[]}_[n].push(s)}}for(const e in _)y[e].keys=_[e].sort(i).map((({key:e})=>e))}return{key:r,map:h,pagePaths:f}}))).then((async e=>{const t={},o=[];return e.filter((e=>null!==e)).forEach((({key:e,map:a,pagePaths:r})=>{t[e]=a,o.push(...r)})),await a.writeTemp("blog/category.js",`export const categoryMap = ${JSON.stringify(t)}\n\nif (import.meta.webpackHot) {\n import.meta.webpackHot.accept()\n if (__VUE_HMR_RUNTIME__.updateBlogCategory) {\n __VUE_HMR_RUNTIME__.updateBlogCategory(categoryMap)\n }\n}\n\nif (import.meta.hot) {\n import.meta.hot.accept(({ categoryMap }) => {\n __VUE_HMR_RUNTIME__.updateBlogCategory(categoryMap)\n })\n}\n`),o}))},p=(a,r,p)=>{const{type:n=[],slugify:s=(e=>e.replace(/[ _]/g,"-").toLowerCase())}=r;return Promise.all(n.map((async({key:r,sorter:n=(()=>-1),filter:i=(()=>!0),path:c="/:key/",layout:l="Layout"},u)=>{if("string"!=typeof r||!r)return t.error(`Invalid 'key' option ${r} in 'category[${u}]'`),null;const g={},y=[];for(const t in p){const u=await e.createPage(a,{path:`${t}${o(s(c.replace(/:key/g,r)))}`,frontmatter:{blog:{type:"type",key:r},layout:l}});a.pages.push(u),y.push(u.path),g[t]={path:u.path,keys:p[t].filter(i).sort(n).map((({key:e})=>e))}}return{key:r,map:g,pagePaths:y}}))).then((async e=>{const t={},o=[];return e.filter((e=>null!==e)).forEach((({key:e,map:a,pagePaths:r})=>{t[e]=a,o.push(...r)})),await a.writeTemp("blog/type.js",`export const typeMap = ${JSON.stringify(t)}\n\nif (import.meta.webpackHot) {\n import.meta.webpackHot.accept()\n if (__VUE_HMR_RUNTIME__.updateBlogType) {\n __VUE_HMR_RUNTIME__.updateBlogType(typeMap)\n }\n}\n\nif (import.meta.hot) {\n import.meta.hot.accept(({ typeMap }) => {\n __VUE_HMR_RUNTIME__.updateBlogType(typeMap)\n })\n}\n`),o}))},n=o=>{const{metaScope:n="_blog",injectMeta:s}=o;let i=[];return{name:"vuepress-plugin-blog2",define:()=>({BLOG_META_SCOPE:n}),onInitialized(e){const n=a(o,e);return Promise.all([r(e,o,n).then((e=>{i.push(...e)})),p(e,o,n).then((e=>{i.push(...e)}))]).then((()=>{e.env.isDebug&&t.info("temp file generated")}))},onWatched(n){const s=[],c=a(o,n);return Promise.all([r(n,o,c).then((e=>{s.push(...e)})),p(n,o,c).then((e=>{s.push(...e)}))]).then((async()=>{if(s.length!==i.length)await e.preparePagesComponents(n),await e.preparePagesData(n),await e.preparePagesRoutes(n);else for(const t of s)i.includes(t)||(await e.preparePagesComponents(n),await e.preparePagesData(n),await e.preparePagesRoutes(n));i=s,n.env.isDebug&&t.info("temp file updated")}))},extendsPage(e){e.routeMeta={...""===n?s?.(e):{[n]:s?.(e)},...e.routeMeta}}}};exports.blog=e=>[n,e],exports.blogPlugin=n,exports.default=n; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "vuepress-plugin-blog2", | ||
"version": "2.0.0-alpha.11", | ||
"version": "2.0.0-alpha.12", | ||
"description": "Blog plugin for VuePress", | ||
@@ -44,3 +44,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@mr-hope/vuepress-shared": "2.0.0-alpha.11", | ||
"@mr-hope/vuepress-shared": "2.0.0-alpha.12", | ||
"@vuepress/client": "2.0.0-beta.35", | ||
@@ -54,3 +54,3 @@ "@vuepress/core": "2.0.0-beta.35", | ||
}, | ||
"gitHead": "497a00a14408ce2cde11edbe5436fff368f39d05" | ||
"gitHead": "a2ecdd81ea138274a45b812c8e190615b48fee83" | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21999
9
229
3
+ Added@mr-hope/vuepress-shared@2.0.0-alpha.12(transitive)
- Removed@mr-hope/vuepress-shared@2.0.0-alpha.11(transitive)