Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ezal

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ezal - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

dist/category.js

2

dist/main.js

@@ -71,3 +71,3 @@ "use strict";

posts: page_1.posts,
categories: page_1.categories,
categories: page_1.categoriesRoot,
tags: page_1.tags,

@@ -74,0 +74,0 @@ };

@@ -15,3 +15,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.updatePage = exports.Post = exports.Page = exports.readPage = exports.readPages = exports.readPosts = exports.tags = exports.categories = exports.posts = exports.pages = void 0;
exports.updatePage = exports.Post = exports.Page = exports.readPage = exports.readPages = exports.readPosts = exports.tags = exports.categoriesRoot = exports.posts = exports.pages = void 0;
const console_1 = require("./console");

@@ -22,2 +22,6 @@ const fs_1 = require("fs");

const yaml_1 = require("yaml");
const category_1 = require("./category");
Object.defineProperty(exports, "categoriesRoot", { enumerable: true, get: function () { return category_1.categoriesRoot; } });
const tag_1 = require("./tag");
Object.defineProperty(exports, "tags", { enumerable: true, get: function () { return tag_1.tags; } });
const pageBase = path_1.default.join(process.cwd(), 'pages');

@@ -31,88 +35,2 @@ const postBase = path_1.default.join(process.cwd(), 'posts');

exports.posts = posts;
let categories = new Map();
exports.categories = categories;
// let categories: Set<category> = new Set();
let tags = new Map();
exports.tags = tags;
/* class category{
name: string;
posts: Set<Post> = new Set();
parent: category | null = null;
children: Set<category> = new Set();
constructor(name: string, parent: category | null){
category._checkName(name, parent);
this.name = name;
if (parent) {
this.parent = parent;
this.parent.addChild(this);
}else{
categories.add(this);
}
}
addChild(child: category){
category._checkName(child.name, this)
categories.delete(child);
this.children.add(child);
if (child.parent) {
child.parent.children.delete(child);
}
child.parent = this;
}
setParent(parent: category){
category._checkName(this.name, parent)
if (this.parent) {
this.parent.children.delete(this);
this.parent = parent;
this.parent.children.add(this);
}else{
categories.delete(this);
this.parent = parent;
this.parent.children.add(this);
}
}
removeParent(){
category._checkName(this.name, null)
if (this.parent) {
this.parent.children.delete(this);
this.parent = null;
}
}
remove(){
if (this.parent) {
this.parent.children.delete(this);
}else{
categories.delete(this)
}
this.posts.forEach((post)=>{
post.categories.delete(this)
})
}
addPost(post: Post){
this.posts.add(post)
post.categories.add(this)
}
removePost(post: Post){
this.posts.delete(post)
post.categories.delete(this)
}
setName(name: string){
category._checkName(name, this.parent)
this.name = name
}
static _checkName(name: string, range: category | null){
let checked = true
if (range) {
range.children.forEach((category)=>{
if (category.name === name) checked = false
})
}else{
categories.forEach((category)=>{
if (category.name === name) checked = false
})
}
if (!checked) {
throw new Error('Cannot set the same name in the same hierarchy.')
}
}
} */
function getFrontMatter(source) {

@@ -205,4 +123,3 @@ try {

this.layout = 'post';
this.categories = new Set();
// categories: Set<category> = new Set();
this.categories = new Map();
this.tags = new Set();

@@ -252,15 +169,3 @@ this.source = '';

}
switch (typeof frontMatter.categories) {
case 'string':
this.addCategory(frontMatter.categories);
break;
case 'object':
if (frontMatter.categories instanceof Array) {
frontMatter.categories.forEach((tag) => {
if (typeof tag === 'string')
this.addCategory(tag);
});
}
break;
}
category_1.Category.initCategories(this, frontMatter.categories);
for (const key in frontMatter) {

@@ -277,39 +182,32 @@ if (Object.prototype.hasOwnProperty.call(frontMatter, key) && !postKeys.includes(key)) {

addTag(name) {
var _a;
this.tags.add(name);
if (tags.has(name)) {
(_a = tags.get(name)) === null || _a === void 0 ? void 0 : _a.add(this);
}
else {
tags.set(name, new Set([this]));
}
tag_1.tags.autoGet(name).addPost(this);
}
removeTag(name) {
var _a;
if (tags.has(name)) {
this.tags.delete(name);
(_a = tags.get(name)) === null || _a === void 0 ? void 0 : _a.delete(this);
}
let target;
this.tags.forEach((tag) => {
if (tag.name === name) {
target = tag;
}
});
if (!target)
return;
target.removePost(this);
}
addCategory(name) {
var _a;
this.categories.add(name);
if (categories.has(name)) {
(_a = categories.get(name)) === null || _a === void 0 ? void 0 : _a.add(this);
}
else {
categories.set(name, new Set([this]));
}
addCategory(path) {
category_1.Category.getByPathAuto(path).addPost(this);
}
removeCategory(name) {
var _a;
if (categories.has(name)) {
this.categories.delete(name);
(_a = categories.get(name)) === null || _a === void 0 ? void 0 : _a.delete(this);
}
removeCategory(path) {
let target = this.categories.get(path);
if (!target)
return;
target.removePost(this);
}
remove() {
posts.delete(this);
this.tags.forEach(this.removeTag);
this.categories.forEach(this.removeCategory);
this.tags.forEach((tag) => {
tag.removePost(this);
});
this.categories.forEach((category) => {
category.removePost(this);
});
for (const key in this) {

@@ -350,3 +248,6 @@ if (Object.prototype.hasOwnProperty.call(this, key) && !postKeys.includes(key)) {

return result;
}).catch((err) => null);
}).catch((err) => {
console.error(err);
return null;
});
}

@@ -353,0 +254,0 @@ exports.readPage = readPage;

@@ -124,7 +124,7 @@ // Type definitions for Ezal 0.0.3

*/
categories: Set<string>
categories: Map<Array<string>, Category>
/**
* Post's tags
*/
tags: Set<string>
tags: Set<Tag>
/**

@@ -160,9 +160,166 @@ * Add a tag in this post

/**
* Category array path
*/
type CategoryPath = Array<string>;
/**
* Categories map
*/
type Categories = Map<string, Category>;
/**
* Category root object model
*/
class CategoryRoot{
/**
* Children category
*/
children: Categories;
/**
* Find subcategories under the current category
* @param path Category array path
*/
query(path: CategoryPath): Category | undefined;
/**
* Add subcategories under the current category
* @param category Category child
*/
addChild(category: Category): void;
/**
* Get subcategories in the current category, or automatically create subcategories if there are none
* @param name Category's name
*/
getChildAuto(name: string): Category;
/**
* Get category's root
*/
static getAll(): Categories;
/**
* Get subcategories at the category root, or automatically create subcategories if there are none
* @param path Category array path
*/
static getByPathAuto(path: CategoryPath): Category;
/**
* Add post to category by path
* @param path Category array path
* @param post Post object
*/
static addPostByPath(path: CategoryPath, post: Post): Category;
/**
* Initialize categories for post
* @param post Post object
* @param object YAML parsed object
*/
static initCategories(post: Post, object: any): void
}
/**
* Category object model
*/
class Category extends CategoryRoot{
/**
* Category's name
*/
name: string;
/**
* Posts under the category
*/
posts: Set<Post>;
/**
* Parent category
*/
parent: Category | CategoryRoot;
/**
* Category's path
*/
path: CategoryPath;
/**
* @param path Category's path
*/
constructor(path: CategoryPath)
/**
* Remove category
*/
remove(): void;
/**
* Add post to this category
* @param post Post object
*/
addPost(post: Post): void;
/**
* Remove post from this category
* @param post Post object
*/
removePost(post: Post): void;
}
/**
* All the categories
*/
export let categories: Map<string, Set<Post>>
export let categories: CategoryRoot;
/**
* Tag root object model
*/
class Tags{
/**
* Create a tag that cannot have the same name as an existing tag
* @param name Tag's name
*/
add(name: string): Tag;
/**
* Remove a tag
* @param tag Tag's name
*/
delete(tag: string): boolean;
/**
* Executes a provided function once per each tag in the tags object, in insertion order.
*/
forEach(callbackfn: (value: Tag, value2: Tag, set: Set<Tag>) => void, thisArg?: any): void;
/**
* Check if tag exists
* @param name Tag's name
*/
has(name: string): boolean;
/**
* Get tag
* @param name Tag's name
*/
get(name: string): Tag | null;
/**
* Get the tag, if it does not exist, it will be created automatically
* @param name Tag's name
*/
autoGet(name: string): Tag;
/**
* @returns The number of tags
*/
readonly size: number;
}
/**
* Tag object model
*/
class Tag{
/**
* Tag's name
*/
name: string;
/**
* Tag's posts
*/
posts: Set<Post>;
/**
* Add post in this tag
* @param post Post object
*/
addPost(post: Post): void;
/**
* Remove post in this tag
* @param post Post object
*/
removePost(post: Post): void;
/**
* Remove this tag
*/
remove(): void;
}
/**
* All the tags
*/
export let tags: Map<string, Set<Post>>
export let tags: Tags | Set<Tag>;
/**

@@ -169,0 +326,0 @@ * Set marked code highlight extension

{
"name": "ezal",
"version": "0.0.3",
"version": "0.0.4",
"description": "",

@@ -34,7 +34,7 @@ "main": "./dist/main.js",

"highlight.js": "^11.8.0",
"katex": "^0.16.7",
"live-server": "^1.2.2",
"marked": "^5.0.2",
"marked-gfm-heading-id": "^3.0.3",
"marked-highlight": "^2.0.0",
"marked-katex": "^0.3.8",
"marked-mangle": "^1.0.1",
"pug": "^3.0.2",

@@ -41,0 +41,0 @@ "stylus": "^0.59.0",

@@ -13,4 +13,4 @@ # Ezal

- [x] Plugin System
- [ ] Typescript support
- [ ] Remake category function
- [ ] Typescript support (optional)
- [x] Remake category function
- [ ] Improve server mode

@@ -30,2 +30,4 @@ - [x] Improve build process

npm install --save marked-highlight
npm install --save marked-gfm-heading-id
npm install --save marked-mangle
npm install --save pug

@@ -32,0 +34,0 @@ npm install --save stylus

@@ -13,4 +13,4 @@ # Ezal

- [x] 插件系统
- [ ] 支持 Typescript
- [ ] 重做分类功能
- [ ] 支持 Typescript(可选)
- [x] 重做分类功能
- [ ] 改进服务器模式

@@ -30,2 +30,4 @@ - [x] 改进构建过程

npm install --save marked-highlight
npm install --save marked-gfm-heading-id
npm install --save marked-mangle
npm install --save pug

@@ -32,0 +34,0 @@ npm install --save stylus

import { info } from "./console";
import readConfig, { checkConfig, checkThemeConfig, readThemeConfig } from "./config";
import { readPages, readPosts, pages, posts, categories, tags, Page, Post, updatePage, readPage } from "./page";
import { readPages, readPosts, pages, posts, categoriesRoot, tags, Page, Post, updatePage, readPage } from "./page";
import { addListener, dispatchEvent } from "./event";

@@ -16,2 +16,4 @@ import { initRenderer, render, renderAll } from "./render";

import { loadScript } from "./script-loader";
type CategoryRoot = import("./category").CategoryRoot;
type Tags = import("./tag").Tags;

@@ -33,4 +35,4 @@ interface EzalModule{

posts: Set<import('./page').Post>;
categories: Map<string, Set<import('./page').Post>>;
tags: Map<string, Set<import('./page').Post>>;
categories: CategoryRoot;
tags: Tags;
setMarkedHighlight?: Function,

@@ -57,3 +59,3 @@ setMarkedExtension?: Function,

posts,
categories,
categories: categoriesRoot,
tags,

@@ -60,0 +62,0 @@ };

@@ -6,2 +6,4 @@ import { error } from "./console";

import { parse } from "yaml";
import { Category, categoriesRoot } from "./category";
import { tags, Tag } from "./tag";

@@ -16,88 +18,3 @@ const pageBase = path.join(process.cwd(), 'pages');

let posts: Set<Post> = new Set();
let categories: Map<string, Set<Post>> = new Map();
// let categories: Set<category> = new Set();
let tags: Map<string, Set<Post>> = new Map();
/* class category{
name: string;
posts: Set<Post> = new Set();
parent: category | null = null;
children: Set<category> = new Set();
constructor(name: string, parent: category | null){
category._checkName(name, parent);
this.name = name;
if (parent) {
this.parent = parent;
this.parent.addChild(this);
}else{
categories.add(this);
}
}
addChild(child: category){
category._checkName(child.name, this)
categories.delete(child);
this.children.add(child);
if (child.parent) {
child.parent.children.delete(child);
}
child.parent = this;
}
setParent(parent: category){
category._checkName(this.name, parent)
if (this.parent) {
this.parent.children.delete(this);
this.parent = parent;
this.parent.children.add(this);
}else{
categories.delete(this);
this.parent = parent;
this.parent.children.add(this);
}
}
removeParent(){
category._checkName(this.name, null)
if (this.parent) {
this.parent.children.delete(this);
this.parent = null;
}
}
remove(){
if (this.parent) {
this.parent.children.delete(this);
}else{
categories.delete(this)
}
this.posts.forEach((post)=>{
post.categories.delete(this)
})
}
addPost(post: Post){
this.posts.add(post)
post.categories.add(this)
}
removePost(post: Post){
this.posts.delete(post)
post.categories.delete(this)
}
setName(name: string){
category._checkName(name, this.parent)
this.name = name
}
static _checkName(name: string, range: category | null){
let checked = true
if (range) {
range.children.forEach((category)=>{
if (category.name === name) checked = false
})
}else{
categories.forEach((category)=>{
if (category.name === name) checked = false
})
}
if (!checked) {
throw new Error('Cannot set the same name in the same hierarchy.')
}
}
} */
function getFrontMatter(source: string) {

@@ -186,5 +103,4 @@ try {

layout: string = 'post';
categories: Set<string> = new Set();
// categories: Set<category> = new Set();
tags: Set<string> = new Set();
categories: Map<Array<string>, Category> = new Map();
tags: Set<Tag> = new Set();
source: string = '';

@@ -230,14 +146,3 @@ context: string = '';

}
switch (typeof frontMatter.categories) {
case 'string':
this.addCategory(frontMatter.categories);
break;
case 'object':
if (frontMatter.categories instanceof Array) {
frontMatter.categories.forEach((tag: any)=>{
if (typeof tag === 'string') this.addCategory(tag);
});
}
break;
}
Category.initCategories(this, frontMatter.categories);
for (const key in frontMatter) {

@@ -254,33 +159,30 @@ if (Object.prototype.hasOwnProperty.call(frontMatter, key) && !postKeys.includes(key)) {

addTag(name: string){
this.tags.add(name);
if (tags.has(name)) {
tags.get(name)?.add(this);
}else{
tags.set(name, new Set([this]));
}
tags.autoGet(name).addPost(this);
}
removeTag(name: string){
if (tags.has(name)) {
this.tags.delete(name);
tags.get(name)?.delete(this);
}
let target: Tag | undefined;
this.tags.forEach((tag)=>{
if (tag.name === name){
target = tag;
}
});
if (!target) return
target.removePost(this);
}
addCategory(name: string){
this.categories.add(name);
if (categories.has(name)) {
categories.get(name)?.add(this);
}else{
categories.set(name, new Set([this]));
}
addCategory(path: Array<string>){
Category.getByPathAuto(path).addPost(this);
}
removeCategory(name: string){
if (categories.has(name)) {
this.categories.delete(name);
categories.get(name)?.delete(this);
}
removeCategory(path: Array<string>){
let target = this.categories.get(path);
if (!target) return;
target.removePost(this);
}
remove(){
posts.delete(this);
this.tags.forEach(this.removeTag);
this.categories.forEach(this.removeCategory);
this.tags.forEach((tag)=>{
tag.removePost(this);
})
this.categories.forEach((category)=>{
category.removePost(this);
});
for (const key in this) {

@@ -318,3 +220,6 @@ if (Object.prototype.hasOwnProperty.call(this, key) && !postKeys.includes(key)) {

return result;
}).catch((err)=>null);
}).catch((err)=>{
console.error(err);
return null
});
}

@@ -348,3 +253,3 @@ async function readPosts() {

posts,
categories,
categoriesRoot,
tags,

@@ -351,0 +256,0 @@ readPosts,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc