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

vite-plugin-press

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

vite-plugin-press - npm Package Compare versions

Comparing version 1.0.6 to 1.0.8

6

client.d.ts

@@ -9,5 +9,7 @@ declare module 'virtual:press' {

export type WhatsNewReleases = { [release: string]: WhatsNew[] }
export type Includes = { includes: Doc[] }
export type PostComponents = { [slug: string]: () => Promise<Component> }
export type VideoComponents = { [group: string]: { [slug: string]: () => Promise<Component> } }
export type WhatsNewComponents = { [release: string]: { [slug: string]: () => Promise<Component> } }
export type IncludesComponents = { [path: string]: () => Promise<Component> }
export type VirtualPress = {

@@ -17,2 +19,3 @@ blog: Blog

whatsNew: WhatsNewReleases
includes: Includes
components: {

@@ -22,5 +25,6 @@ blog: PostComponents

whatsNew: WhatsNewComponents
includes: IncludesComponents
}
}
export type Doc = {

@@ -27,0 +31,0 @@ title: string

@@ -41,2 +41,18 @@ import { Plugin } from 'vite';

/**
* Where to look for Includes
* @default './src/_includes'
*/
includesPath?: string
/**
* Where to publish json metadata
*/
metadataPath?: string
/**
* Which markdown properties to export in metadata
*/
exportProps?: string[]
/**
* Fallback Author profile url

@@ -51,2 +67,7 @@ */

fallbackPostImageUrl?: string
/**
* Base URL for the site to resolve absolute URLs
*/
baseUrl?: string
}

@@ -64,5 +85,7 @@

type WhatsNewReleases = { [release: string]: WhatsNew[] }
type Includes = { includes: Doc[] }
type PostComponents = { [slug: string]: () => Promise<Component> }
type VideoComponents = { [group: string]: { [slug: string]: () => Promise<Component> } }
type WhatsNewComponents = { [release: string]: { [slug: string]: () => Promise<Component> } }
type IncludesComponents = { [path: string]: () => Promise<Component> }
type VirtualPress = {

@@ -72,2 +95,3 @@ blog: Blog

whatsNew: WhatsNewReleases
includes: Includes
components: {

@@ -77,2 +101,3 @@ blog: PostComponents

whatsNew: WhatsNewComponents
includes: IncludesComponents
}

@@ -79,0 +104,0 @@ }

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

}
function createDoc(filePath, options = {}) {
function createDoc(filePath, _options = {}) {
filePath = filePath.replaceAll("\\", "/");

@@ -190,3 +190,3 @@ const file = lastRightPart(filePath, "/");

const config = fromDirExists && import_fs2.default.existsSync(configPath) ? JSON.parse(import_fs2.default.readFileSync(configPath, "utf-8")) : {};
const files = fromDirExists ? import_fs2.default.readdirSync(fromDir).filter((x) => import_fs2.default.statSync(import_path.default.join(fromDir, x)).isFile() && x.endsWith(".md")) : [];
const files = fromDirExists ? import_fs2.default.readdirSync(fromDir).filter((x) => import_fs2.default.statSync(import_path.default.join(fromDir, x)).isFile() && (x.endsWith(".md") || x.endsWith(".mdx"))) : [];
if (!fromDirExists) {

@@ -245,3 +245,3 @@ return { config, authors, posts, authorSlugs, tagSlugs };

if (!options.quiet) {
const count = dirs.reduce((acc, x) => acc + import_fs3.default.readdirSync(import_path2.default.join(fromDir, x)).length, 0);
const count = dirs.reduce((acc, x) => acc + import_fs3.default.readdirSync(import_path2.default.join(fromDir, x)).filter((x2) => x2.endsWith(".md") || x2.endsWith(".mdx")).length, 0);
const plural = count > 1 ? "s" : "";

@@ -252,3 +252,3 @@ console.log(`Found ${dirs.length} Video Group${dirs.length > 1 ? "s" : ""} with ${count} Video${plural}`);

const group = dir;
import_fs3.default.readdirSync(import_path2.default.join(fromDir, dir)).forEach((file) => {
import_fs3.default.readdirSync(import_path2.default.join(fromDir, dir)).filter((x) => x.endsWith(".md") || x.endsWith(".mdx")).forEach((file) => {
const filePath = import_path2.default.join(fromDir, dir, file);

@@ -289,3 +289,3 @@ if (!groups[group])

if (!options.quiet) {
const count = dirs.reduce((acc, x) => acc + import_fs4.default.readdirSync(import_path3.default.join(fromDir, x)).length, 0);
const count = dirs.reduce((acc, x) => acc + import_fs4.default.readdirSync(import_path3.default.join(fromDir, x)).filter((x2) => x2.endsWith(".md") || x2.endsWith(".mdx")).length, 0);
const plural = count > 1 ? "s" : "";

@@ -310,3 +310,3 @@ console.log(`Found ${dirs.length} What's New Release${dirs.length > 1 ? "s" : ""} with ${count} Feature${plural}`);

const releaseVersion = rightPart(release, "_");
import_fs4.default.readdirSync(import_path3.default.join(fromDir, dir)).forEach((file) => {
import_fs4.default.readdirSync(import_path3.default.join(fromDir, dir)).filter((x) => x.endsWith(".md") || x.endsWith(".mdx")).forEach((file) => {
var _a;

@@ -340,2 +340,147 @@ const filePath = import_path3.default.join(fromDir, dir, file);

// src/includes.ts
var import_fs5 = __toESM(require("fs"));
var import_path4 = __toESM(require("path"));
function loadFrom4(fromDir, options = {}) {
const includes = [];
const fromDirExists = import_fs5.default.existsSync(fromDir);
const files = fromDirExists ? import_fs5.default.readdirSync(fromDir, { recursive: true }).filter((x) => typeof x == "string" && import_fs5.default.statSync(import_path4.default.join(fromDir, x)).isFile() && (x.endsWith(".md") || x.endsWith(".mdx"))) : [];
if (!fromDirExists) {
return { includes };
}
if (!options.quiet) {
const plural = files.length > 1 ? "s" : "";
console.log(`Found ${files.length} Include${plural}`);
}
files.forEach((file) => {
const filePath = import_path4.default.join(fromDir, file);
const doc = createDoc(filePath, options);
if (!doc)
return;
doc.slug = lastLeftPart(doc.fileName, ".");
doc.group = file.replaceAll("\\", "/").substring(0, file.length - doc.fileName.length - 1);
if (process.env.NODE_ENV != "development" && doc.draft) {
return;
}
includes.push(doc);
});
return { includes };
}
function generateComponents4({ includes }) {
return [
`{`,
...includes.map((doc) => `"${doc.group ? doc.group + "/" + doc.fileName : doc.fileName}": () => import('/${doc.path}'),`),
`}`
].map((line) => ` ${line}`).join("\n");
}
// src/metadata.ts
var import_fs6 = __toESM(require("fs"));
var import_path5 = __toESM(require("path"));
var defaultExportProps = ["slug", "title", "summary", "fileName", "date", "tags", "author", "image", "wordCount", "lineCount", "url", "group", "order"];
function pick(o, keys) {
const to = {};
for (const k in o) {
if (o.hasOwnProperty(k) && keys.indexOf(k) >= 0) {
to[k] = o[k];
}
}
return to;
}
function sortBy(o, sorters) {
o.sort((a, b) => {
for (let i = 0; i < sorters.length; i++) {
const fn = sorters[i];
const result = fn(a, b);
if (result != 0)
return result;
}
return 0;
});
return o;
}
var exportDoc = (data, exportProps) => pick(data, exportProps);
var Data = {
blog(blog) {
const { posts } = blog;
return posts.map((x) => {
x.url = `/posts/${x.slug}`;
return x;
});
},
videos(videos) {
return Object.values(videos).flatMap((x) => x.map((x2) => {
return x2;
}));
},
whatsNew(whatsNew) {
return Object.values(whatsNew).flatMap((x) => x.map((x2) => {
return x2;
}));
}
};
function generateMetadata(data, options) {
var _a;
const { toDir, baseUrl } = options;
const exportProps = (_a = options.exportProps) != null ? _a : defaultExportProps;
if (!toDir) {
console.error("toDir is required", options);
return;
}
if (import_fs6.default.existsSync(toDir)) {
import_fs6.default.rmdirSync(toDir, { recursive: true });
}
import_fs6.default.mkdirSync(toDir, { recursive: true });
const featureDocs = {};
const allYears = /* @__PURE__ */ new Set();
const index = {};
Object.keys(data).forEach((key) => {
const fn = Data[key];
if (!fn)
return;
const allDocs = sortBy(fn(data[key]).map((x) => exportDoc(x, exportProps)), [
(a, b) => a.date > b.date ? -1 : a.date < b.date ? 1 : 0,
(a, b) => {
var _a2, _b;
return ((_a2 = a.order) != null ? _a2 : 0) - ((_b = b.order) != null ? _b : 0);
},
(a, b) => a.fileName.localeCompare(b.fileName)
]);
if (baseUrl) {
let urlPrefix = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length - 1) : baseUrl;
allDocs.forEach((doc) => {
var _a2, _b;
if ((_a2 = doc.url) == null ? void 0 : _a2.startsWith("/"))
doc.url = urlPrefix + doc.url;
if ((_b = doc.image) == null ? void 0 : _b.startsWith("/"))
doc.image = urlPrefix + doc.image;
});
}
featureDocs[key] = allDocs;
const featureYears = new Set(allDocs.filter((x) => x.date).map((x) => new Date(x.date).getFullYear()));
featureYears.forEach((year) => allYears.add(year));
index[key] = Array.from(featureYears).map((year) => (baseUrl != null ? baseUrl : "") + `/meta/${year}/${key}.json`);
featureYears.forEach((year) => {
const yearDocs = allDocs.filter((x) => x.date && new Date(x.date).getFullYear() == year);
const yearDir = import_path5.default.join(toDir, `${year}`);
import_fs6.default.mkdirSync(yearDir, { recursive: true });
const metaPath = import_path5.default.join(yearDir, `${key}.json`);
import_fs6.default.writeFileSync(metaPath, JSON.stringify(yearDocs, void 0, 4));
});
import_fs6.default.writeFileSync(import_path5.default.join(toDir, "index.json"), JSON.stringify(index, void 0, 4));
import_fs6.default.writeFileSync(import_path5.default.join(toDir, "all.json"), JSON.stringify(featureDocs, void 0, 4));
const sortedYears = Array.from(allYears);
sortedYears.sort((a, b) => b - a);
sortedYears.forEach((year) => {
const yearDocs = {};
Object.entries(featureDocs).forEach(([feature, docs]) => {
yearDocs[feature] = docs.filter((x) => x.date && new Date(x.date).getFullYear() == year);
});
const yearDir = import_path5.default.join(toDir, `${year}`);
import_fs6.default.mkdirSync(yearDir, { recursive: true });
import_fs6.default.writeFileSync(import_path5.default.join(yearDir, `all.json`), JSON.stringify(yearDocs, void 0, 4));
});
});
}
// src/index.ts

@@ -345,6 +490,7 @@ var videosPath = "./src/_videos";

var whatsNewPath = "./src/_whatsnew";
var includesPath = "./src/_includes";
var fallbackAuthorProfileUrl = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 4a4 4 0 0 1 4 4a4 4 0 0 1-4 4a4 4 0 0 1-4-4a4 4 0 0 1 4-4m0 10c4.42 0 8 1.79 8 4v2H4v-2c0-2.21 3.58-4 8-4'/%3E%3C/svg%3E";
var fallbackPostImageUrl = "https://source.unsplash.com/random/2000x1000/?stationary";
function src_default(options = {}) {
options = Object.assign({ fallbackAuthorProfileUrl, fallbackPostImageUrl, videosPath, postsPath, whatsNewPath }, options);
options = Object.assign({ fallbackAuthorProfileUrl, fallbackPostImageUrl, videosPath, postsPath, whatsNewPath, includesPath }, options);
const virtualModuleId = "virtual:press";

@@ -366,5 +512,13 @@ const resolvedVirtualModuleId = "\0" + virtualModuleId;

const whatsNew = loadFrom3(options.whatsNewPath);
const includes = loadFrom4(options.includesPath);
if (options.metadataPath) {
generateMetadata(
{ blog, videos, whatsNew },
{ toDir: options.metadataPath, baseUrl: options.baseUrl, exportProps: options.exportProps }
);
}
const blogComponents = generateComponents(blog);
const videoComponents = generateComponents2(videos);
const whatsNewComponents = generateComponents3(whatsNew);
const includesComponents = generateComponents4(includes);
const sb = [

@@ -382,2 +536,4 @@ `export default {`,

whatsNewComponents + ",",
` includes:`,
includesComponents + ",",
` }`,

@@ -384,0 +540,0 @@ "}"

2

package.json
{
"name": "vite-plugin-press",
"version": "1.0.6",
"version": "1.0.8",
"description": "Static markdown content for creating blogs, videos",

@@ -5,0 +5,0 @@ "repository": {

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