Socket
Socket
Sign inDemoInstall

markedpage

Package Overview
Dependencies
8
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.13 to 0.1.14

dist/common-48ec8bf3.js

163

dist/index.d.ts

@@ -1,86 +0,95 @@

import { Plugin } from 'vite';
interface SourcePage extends Record<string, any> {
frontMatter: Record<string, any>;
sourcePath: PathLike | string;
indexPath: PathLike | string;
headings: Array<HeadingItem>;
render: (() => Promise<string>) | any;
raw: () => Promise<string>;
slugKey: string;
declare module "markedpage/helper" {
export const onContentUpdate: (callback: (payload: Record<string, any>) => void) => void;
}
interface PageMapCollection {
pathMap: Record<string, SourcePage>;
slugMap: Record<string, Array<SourcePage>>;
declare module "markedpage" {
export interface SourcePage extends Record<string, any> {
frontMatter: Record<string, any>;
sourcePath: string;
indexPath: string;
headings: Array<HeadingItem>;
render: (() => Promise<string>) | any;
raw: () => Promise<string>;
slugKey: string;
}
export interface PageMapCollection {
pathMap: Record<string, SourcePage>;
slugMap: Record<string, Array<SourcePage>>;
}
export interface HeadingItem extends Record<string, any> {
depth: number;
text: string;
raw: string;
id: string;
}
export interface ClassifierOptions<Locals = Record<string, any>> {
id: string;
type: ClassifierType;
params: Locals;
}
export interface ClassifierHandle<Locals = Record<string, any>, Result = Record<string, any>> {
(input: {
options: ClassifierOptions<Locals>;
pages: Array<SourcePage> | any;
}): Promise<Result>;
}
export type ClassifierType = 'directory' | 'frontmatter' | ClassifierHandle;
export interface DirectoryClassifierResult {
pages: Array<SourcePage>;
}
export type FrontMatterClassifierResult = Record<string, Array<SourcePage>>;
}
interface HeadingItem extends Record<string, any> {
depth: number;
text: string;
raw: string;
id: string;
declare module "markedpage" {
export const logger: {
debug: (message: any, ...options: any[]) => void;
warn: (message: any, ...options: any[]) => void;
error: (message: any, ...options: any[]) => void;
info: (message: any, ...options: any[]) => void;
};
}
type ClassifierType = 'directory' | 'frontmatter' | ClassifierHandle;
interface ClassifierOptions<Locals = Record<string, any>> {
id: string;
type: ClassifierType;
params: Locals;
declare module "markedpage" {
/**
* Get siteConfig
*
* @async
* @return {Promise<Record<string, any>>} custom config.
*/
export const siteConfig: () => Promise<Record<string, any>>;
/**
* Get All source page, index by indexPath
*
* @async
* @return {Promise<Record<string, SourcePage>>} key: IndexPath value: SourcePage
*/
export const pathMap: () => Promise<Record<string, SourcePage>>;
/**
* Get All source page, index by slugName
*
* @async
* @return {Promise<Record<string, Array<SourcePage>>>}
*/
export const slugMap: () => Promise<Record<string, Array<SourcePage>>>;
/**
* Get classified pages set.
*
* @async
* @param {string} classifierId
* @return {Promise<Record<string,any>>}
*/
export const classifiedSet: (classifierId: string) => Promise<any>;
/**
* Get page by key.
* @param indexKey SlugKey | indexPath
* @param slugMatchFunc
* @returns
*/
export const getPage: (indexKey: string, slugMatchFunc?: (page: SourcePage) => boolean) => Promise<SourcePage>;
export const pageMap: () => Promise<import("types").PageMapCollection>;
}
interface ClassifierHandle$1<Locals = Record<string, any>, Result = Record<string, any>> {
(input: {
options: ClassifierOptions<Locals>;
pages: Array<SourcePage> | any;
}): Promise<Result>;
declare module "markedpage" {
import type { Plugin } from "vite";
export const markedpageVitePlugin: (siteConfig?: Record<string, any>) => Plugin;
}
interface DirectoryClassifierResult {
pages: Array<SourcePage>;
}
declare type FrontMatterClassifierResult = Record<string, Array<SourcePage>>;
/**
* Get siteConfig
*
* @async
* @return {Promise<Record<string, any>>} custom config.
*/
declare const siteConfig: () => Promise<Record<string, any>>;
/**
* Get All source page, index by indexPath
*
* @async
* @return {Promise<Record<string, SourcePage>>} key: IndexPath value: SourcePage
*/
declare const pathMap: () => Promise<Record<string, SourcePage>>;
/**
* Get All source page, index by slugName
*
* @async
* @return {Promise<Record<string, Array<SourcePage>>>}
*/
declare const slugMap: () => Promise<Record<string, Array<SourcePage>>>;
/**
* Get classified pages set.
*
* @async
* @param {string} classifierId
* @return {Promise<Record<string,any>>}
*/
declare const classifiedSet: (classifierId: string) => Promise<any>;
/**
* Get page by key.
* @param indexKey SlugKey | indexPath
* @param slugMatchFunc
* @returns
*/
declare const getPage: (indexKey: string, slugMatchFunc?: (page: SourcePage) => boolean) => Promise<SourcePage>;
declare const onContentUpdate: (callback: (payload: Record<string, any>) => void) => void;
declare const markedpageVitePlugin: (siteConfig?: Record<string, any>) => Plugin;
export { ClassifierHandle$1 as ClassifierHandle, DirectoryClassifierResult, FrontMatterClassifierResult, PageMapCollection, SourcePage, classifiedSet, getPage, markedpageVitePlugin, onContentUpdate, pathMap, siteConfig, slugMap };
{
"version": "0.1.13",
"version": "0.1.14",
"name": "markedpage",
"type": "module",
"description": "Markdown source provider & classification utilities",
"main": "dist/index.js",
"module": "dist/index.mjs",
"scripts": {
"build": "rollup -c",
"test": "uvu -r tsm test test.ts$",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"files": [
"dist/*"
"dist"
],
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.mjs.d.ts"
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./helper": {
"import": "./dist/helper.js",
"types": "./dist/helper.d.ts"
}
},

@@ -29,3 +29,3 @@ "devDependencies": {

"@types/marked": "^4.0.5",
"@types/node": "^18.7.6",
"@types/node": "^18.7.8",
"@types/remove-markdown": "^0.3.1",

@@ -38,5 +38,6 @@ "@typescript-eslint/eslint-plugin": "^4.33.0",

"prettier": "^2.7.1",
"rollup": "^2.78.0",
"rollup-plugin-dts": "^4.2.2",
"rimraf": "^3.0.2",
"rollup": "^2.78.1",
"rollup-plugin-exclude-dependencies-from-bundle": "^1.1.22",
"rollup-plugin-flat-dts": "^1.6.1",
"tslib": "^2.4.0",

@@ -46,3 +47,3 @@ "tsm": "^2.2.2",

"uvu": "^0.5.6",
"vite": "^3.0.8"
"vite": "^3.0.9"
},

@@ -53,3 +54,2 @@ "repository": {

},
"type": "module",
"license": "MIT",

@@ -68,3 +68,10 @@ "author": "Saweima <saweima12@gmail.com>",

"remove-markdown": "^0.5.0"
}
}
},
"scripts": {
"build": "rimraf -R dist && rollup -c",
"test": "uvu -r tsm test test.ts$",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"readme": "# MarkedPage\n\nA Markdown provider for my sveltekit static blog.\n\n## Features\n\n- Markdown source provide\n- Customize Classification\n- Support `<!-- more -->` tag, it will add excerpt into frontmatter\n- Use marked to parse markdown context.\n\n## Usage\n\n1. Create **./src/site.config.js** to configure setting.\n\n```js\nconst config = {\n title: 'TestWebSite',\n classifier: [\n { id: 'post', params: { path: '/_posts/' }, type: 'directory' },\n { id: 'tag', params: { keys: ['tag', 'tags'] }, type: 'frontmatter' }\n ],\n marked: {\n options: {},\n extensions: {}\n }\n};\n\nexport default config;\n```\n\n2. Create **./docs/\\_posts/2022-04-28-post1.md** and put markdown files in it.\n\n```\n/\n|_docs\n |_posts\n |_2022-04-28-post1.md\n```\n\n3. Use **getPage** or **classifiedSet** to get page context or page list in endpoints.\n\n```js\n// example.ts\nimport type { DirectoryClassifierResult } from 'markedpage';\nimport { getPage, classifiedSet } from 'markedpage';\nimport type { RequestHandler } from '@sveltejs/kit';\n\nexport const get: RequestHandler = async () => {\n // Get list.\n const pageSet: DirectoryClassifierResult = await classifiedSet('post');\n const pages = pageSet.pages;\n // Get page.\n const page = await getPage('post1');\n const context = await page.render();\n\n return {\n body: {\n pages: pages,\n metadata: page.frontMatter,\n body: context\n }\n };\n};\n```\n\n## Example\n\n```md\n<!-- 2022-04-28-firstpage.md -->\n\ntitle: FirstPost\ntags:\n- test\n---\n\nThis is summary field.\n\n<!-- more -->\n\nThis is context block.\n```\n\nIt will be passed to\n\n```\n{\n frontMatter: {\n title: 'FirstPost',\n tags: [ 'test' ],\n excerpt: 'This is summary field.',\n created: 2022-04-28T00:00:00.000Z\n },\n sourcePath: 'docs/2022-04-28-firstpage.md',\n indexPath: 'docs/2022-04-28-firstpage',\n render: [Function: render],\n raw: [Function: raw],\n slugKey: 'firstpage'\n}\n```\n\n## Markdown Vite HMR Support \n\n- Add `markedpageVitePlugin()` to config.plugins\n```js\n// vite.config.js\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { markedpageVitePlugin } from 'markedpage';\n\nimport siteConfig from './src/site.config.js';\n\n/** @type {import('vite').UserConfig} */\nconst config = {\n\tplugins: [sveltekit(), markedpageVitePlugin(siteConfig)]\n};\n\nexport default config;\n```\n\n- Listen to onContentUpdate and update the endpoint with invalidate.\n```js\n// src/routes/\n<script lang=\"ts\">\n import { invalidate } from '$app/navigation';\n import { page } from '$app/stores';\n import { onContentUpdate } from 'markedpage/helper';\n \n onContentUpdate((payload) => {\n let slug = $page.params.slug;\n // update endpoint data.\n invalidate(`/api/posts.json`);\n invalidate(`/api/posts/${slug}.json`);\n });\n</script>\n```\n\n## Example\n\nhttps://github.com/saweima12/markedpage-example\n\n## ChangeLog\n- [2022-08-22] v0.1.14 - **breaking**Move `onContentUpdate` to `markedpage/helper` [[issues](https://github.com/saweima12/markedpage/issues/2)]\n- [2022-08-18] v0.1.13 - Optimize markdown file reload.\n- [2022-07-22] v0.1.10 - Fix: marked config is not loaded properly\n- [2022-07-22] v0.1.8 - Add support for site.config.js auto-reload via configuration \n- [2022-07-18] v0.1.7 - Replace chalk.js with kleur\n- [2022-07-16] v0.1.5 - Add markdown file Vite HMR Support.\n- [2022-05-31] Add `_draft` field support in FrontMatter.(It will not be added to list in production)\n- [2022-05-27] Add extendPageData support\n"
}

@@ -124,12 +124,12 @@ # MarkedPage

<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { onContentUpdate } from 'markedpage';
onContentUpdate((payload) => {
let slug = $page.params.slug;
// update endpoint data.
invalidate(`/api/posts.json`);
invalidate(`/api/posts/${slug}.json`);
});
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { onContentUpdate } from 'markedpage/helper';
onContentUpdate((payload) => {
let slug = $page.params.slug;
// update endpoint data.
invalidate(`/api/posts.json`);
invalidate(`/api/posts/${slug}.json`);
});
</script>

@@ -143,2 +143,3 @@ ```

## ChangeLog
- [2022-08-22] v0.1.14 - **breaking**Move `onContentUpdate` to `markedpage/helper` [[issues](https://github.com/saweima12/markedpage/issues/2)]
- [2022-08-18] v0.1.13 - Optimize markdown file reload.

@@ -145,0 +146,0 @@ - [2022-07-22] v0.1.10 - Fix: marked config is not loaded properly

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc