New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vuepress-plugin-feed2

Package Overview
Dependencies
Maintainers
1
Versions
307
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuepress-plugin-feed2 - npm Package Compare versions

Comparing version 2.0.0-alpha.5 to 2.0.0-alpha.6

3

node/index.d.ts

@@ -298,3 +298,2 @@ import { Page, Plugin } from '@vuepress/core';

export default feedPlugin;
export { FeedAuthor, FeedCategory, FeedChannelOption, FeedContributor, FeedEnclosure, FeedFrontmatterOption, FeedInitOptions, FeedItemOption, FeedLinks, FeedOptions, FeedOutput, FeedPluginFrontmatter };
export { FeedAuthor, FeedCategory, FeedChannelOption, FeedContributor, FeedEnclosure, FeedFrontmatterOption, FeedInitOptions, FeedItemOption, FeedLinks, FeedOptions, FeedOutput, FeedPluginFrontmatter, feedPlugin as default };

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@mr-hope/vuepress-shared"),e=require("chalk"),r=require("fs-extra");function a(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,a.get?a:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var o=a(require("xml-js"));const n=new t.Logger("Feed"),i=t=>t.replace(/ class=".*?"/gu,"").replace(/ v-pre/gu,"").replace(/<a href="#.*?">.*?<\/a>/gu,"").replace(/<!--.*?-->/gu,"").replace(/<OutboundLink ?\/>/gu,"").replace(/<RouterLink to="(.*?)">(.*?)<\/RouterLink>/gu,'<a href="$1">$2</a>').replace(/<(?:a|div|span)[^>]*?\/>/gu,"").replace(/<(Badge|FlowChart|Presentation).*?(?:>.*?<\/\1>|\/>)/gu,"<i>Content not supported</i>").replace(/<math[\s\S]*?\/math>/gu,"<i>Content not supported</i>"),s=(t,e="",r="")=>`${t}${e.replace(/^\/?/u,"/").replace(/\/?$/u,"/")}${r.replace(/^\//u,"")}`,p=(t="")=>`image/${"jpg"===t?"jpeg":"svg"===t?"svg+xml":"jpeg"===t||"png"===t||"bmp"===t||"gif"===t||"webp"===t?t:""}`,c=e=>t.deepAssign({atom:{enable:!0,path:"atom.xml"},json:{enable:!0,path:"feed.json"},rss:{enable:!0,path:"rss.xml"}},e||{}),u=e=>{const{name:r,email:a,url:o}=e;return{name:r,...a?{email:a}:{},...o?{uri:t.encodeXML(o)}:{}}},h=t=>{const{name:e,scheme:r}=t;return{_attributes:{term:e,scheme:r}}},l=t=>({name:t.name,...t.url?{url:t.url}:{},...t.avator?{avator:t.avator}:{}}),d=t=>{const{name:e,domain:r}=t;return{_text:e,...r?{_attributes:{domain:r}}:{}}},g=e=>{const r=e.guid||t.encodeXML(e.link);return{...t.isUrl(r)?{}:{_attributes:{isPermaLink:!1}},_text:r}};class m{options;items=[];categories=new Set;_contributorKeys=new Set;contributors=[];constructor(t){this.options=t}addItem=t=>{this.items.push(t)};addCategory=t=>{this.categories.add(t)};addContributor=t=>{const e=t.email||t.name;e&&!this._contributorKeys.has(e)&&(this._contributorKeys.add(e),this.contributors.push(t))};atom=()=>(e=>{const{channel:r,links:a}=e.options,n={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}},feed:{_attributes:{xmlns:"http://www.w3.org/2005/Atom",...r.language?{"xml:lang":r.language}:{}},id:r.link,title:r.title,...r.description?{subtitle:r.description}:{},...r.author?{author:u(r.author)}:{},updated:r.lastUpdated?r.lastUpdated.toISOString():(new Date).toISOString(),generator:"vuepress-plugin-feed2",link:[{_attributes:{rel:"self",href:t.encodeXML(a.atom)}}]}};return r.link&&n.feed.link.push({_attributes:{rel:"alternate",href:t.encodeXML(r.link)}}),r.hub&&n.feed.link.push({_attributes:{rel:"hub",href:t.encodeXML(r.hub)}}),r.image&&(n.feed.logo=r.image),r.icon&&(n.feed.icon=r.icon),r.copyright&&(n.feed.rights=r.copyright),n.feed.category=Array.from(e.categories).map((t=>({_attributes:{term:t}}))),n.feed.contributor=Array.from(e.contributors).filter((t=>t.name)).map((t=>u(t))),n.feed.entry=e.items.map((e=>{const r={title:{_attributes:{type:"html"},_text:t.encodeXML(e.title)},id:t.encodeXML(e.guid||e.link),link:{_attributes:{href:t.encodeXML(e.link)}},updated:e.lastUpdated.toISOString()};return e.description&&(r.summary={_attributes:{type:"html"},_cdata:t.encodeCDATA(e.description)}),e.content&&(r.content={_attributes:{type:"html"},_cdata:t.encodeCDATA(e.content)}),Array.isArray(e.author)?r.author=e.author.filter((t=>t.name)).map((t=>u(t))):e.author&&e.author.name&&(r.author=[u(e.author)]),Array.isArray(e.category)?r.category=e.category.map((t=>h(t))):e.category&&(r.category=[h(e.category)]),Array.isArray(e.contributor)&&(r.contributor=e.contributor.map((t=>u(t)))),e.pubDate&&(r.published=e.pubDate.toISOString()),e.copyright&&(r.rights=e.copyright),r})),o.js2xml(n,{compact:!0,ignoreComment:!0,spaces:2})})(this);rss=()=>(e=>{const{links:r,channel:a}=e.options;let n=!1;const i={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}},rss:{_attributes:{version:"2.0","xmlns:atom":"http://www.w3.org/2005/Atom"},channel:{"atom:link":{_attributes:{href:r.rss,rel:"self",type:"application/rss+xml"}},title:{_text:a.title},link:{_text:t.encodeXML(a.link)},description:{_text:a.description},language:{_text:t.encodeXML(a.language)},pubDate:{_text:a.pubDate?a.pubDate.toUTCString():(new Date).toUTCString()},lastBuildDate:{_text:a.lastUpdated?a.lastUpdated.toUTCString():(new Date).toUTCString()},generator:{_text:"vuepress-plugin-feed2"},docs:{_text:"https://validator.w3.org/feed/docs/rss2.html"}}}};return a.copyright&&(i.rss.channel.copyright={_text:a.copyright}),a.ttl&&(i.rss.channel.ttl={_text:a.ttl.toString()}),a.image&&(i.rss.channel.image={title:{_text:a.title},url:{_text:a.image},link:{_text:t.encodeXML(a.link)}}),i.rss.channel.category=Array.from(e.categories).map((t=>({_text:t}))),i.rss.channel.item=e.items.map((e=>{const a={title:{_text:t.encodeXML(e.title)},link:{_text:t.encodeXML(e.link)},guid:g(e),source:{_attributes:{url:r.rss},_text:e.title}};if(e.description&&(a.description={_text:t.encodeXML(e.description)}),Array.isArray(e.author)){const t=e.author.find((t=>t.email&&t.name));t&&(a.author={_text:`${t.email} (${t.name})`})}else if("object"==typeof e.author){const{name:t,email:r}=e.author;r&&t&&(a.author={_text:`${r} (${t})`})}var o;return Array.isArray(e.category)?a.category=e.category.filter((t=>t.name)).map((t=>d(t))):"object"==typeof e.category&&e.category.name&&(a.category=[d(e.category)]),e.comments&&(a.comments={_text:t.encodeXML(e.link)}),e.pubDate&&(a.pubDate={_text:e.pubDate.toUTCString()}),e.content&&(n=!0,a["content:encoded"]={_cdata:t.encodeCDATA(e.content)}),e.enclosure&&(a.enclosure={_attributes:{url:(o=e.enclosure).url,...o.length?{length:o.length}:{},...o.type?{type:o.type}:{}}}),a})),n&&(i.rss._attributes["xmlns:content"]="http://purl.org/rss/1.0/modules/content/",i.rss._attributes["xmlns:dc"]="http://purl.org/dc/elements/1.1/"),o.js2xml(i,{compact:!0,ignoreComment:!0,spaces:2})})(this);json=()=>(t=>{const{channel:e,links:r}=t.options,a={version:"https://jsonfeed.org/version/1.1",title:e.title,home_page_url:e.link,feed_url:r.json};return e.description&&(a.description=e.description),e.image&&(a.icon=e.image),e.icon&&(a.favicon=e.icon),e.author?.name&&(a.author={name:e.author.name,...e.author.url?{url:e.author.url}:{},...e.author.avator?{avator:e.author.avator}:{}}),a.items=t.items.map((t=>{const e={title:t.title,url:t.link,id:t.guid||t.link,...t.description?{summary:t.description}:{},content_html:t.content};return t.image&&(e.image=t.image),t.pubDate&&(e.date_published=t.pubDate.toISOString()),t.lastUpdated&&(e.date_modified=t.lastUpdated.toISOString()),Array.isArray(t.author)?e.authors=t.author.filter((t=>t.name)).map((t=>l(t))):"object"==typeof t.author&&(e.authors=[l(t.author)]),Array.isArray(t.category)?e.tags=t.category.filter((t=>t.name)).map((t=>t.name)):t.category&&(e.tags=[t.category.name]),e})),JSON.stringify(a,null,2)})(this)}class f{page;feed;options;app;feedOption;frontmatter;base;themeConfig;constructor(t,e,r,a){this.page=t,this.feed=e,this.options=r,this.app=a,this.frontmatter=t.frontmatter,this.feedOption=this.frontmatter.feed||{},this.base=this.app.options.base,this.themeConfig=this.app.options.themeConfig}get title(){return this.feedOption.title||this.page.title}get link(){return s(this.options.hostname,this.base,this.page.path)}get description(){return this.feedOption.description?this.feedOption.description:this.frontmatter.description?this.frontmatter.description:this.page.excerpt?i(this.app.markdown.render(this.page.excerpt)):void 0}get author(){return Array.isArray(this.feedOption.author)?this.feedOption.author:"object"==typeof this.feedOption.author?[this.feedOption.author]:!1===this.frontmatter.author?[]:t.getAuthor(this.frontmatter,this.themeConfig).map((t=>({name:t})))}get category(){if(Array.isArray(this.feedOption.category))return this.feedOption.category;if("object"==typeof this.feedOption.category)return[this.feedOption.category];const{categories:e,category:r=e}=this.frontmatter;return t.getCategory(r).map((t=>({name:t})))}get enclosure(){if(this.image)return{url:this.image,type:p(this.image.split(".").pop())}}get guid(){return this.feedOption.guid||this.link}get pubDate(){const{time:t,date:e=t}=this.page.frontmatter,{createdTime:r}=this.page.git||{};return e&&e instanceof Date?e:r?new Date(r):void 0}get lastUpdated(){const{updatedTime:t}=this.page.git||{};return t?new Date(t):new Date}get content(){return this.feedOption.content?this.feedOption.content:i(this.page.componentFileContent.replace(/<template>.*<\/template>/,"$1"))}get image(){const{banner:e,cover:r}=this.frontmatter;if(e){if(t.isAbsoluteUrl(e))return s(this.options.hostname,this.app.options.base,e);if(t.isUrl(e))return e}if(r){if(t.isAbsoluteUrl(r))return s(this.options.hostname,this.app.options.base,r);if(t.isUrl(r))return r}const a=/!\[.*?\]\((.*?)\)/iu.exec(this.page.content);if(a){if(t.isAbsoluteUrl(a[1]))return s(this.options.hostname,this.app.options.base,a[1]);if(t.isUrl(a[1]))return a[1]}}get contributor(){return Array.isArray(this.feedOption.contributor)?this.feedOption.contributor:"object"==typeof this.feedOption.contributor?[this.feedOption.contributor]:this.author}get copyright(){if(this.frontmatter.copyrightText)return this.frontmatter.copyrightText;const t=this.author[0];return t&&t.name?`Copyright by ${t.name}`:void 0}getFeedItem(){const{author:t,category:e,content:r,contributor:a,copyright:o,description:n,enclosure:i,guid:s,image:p,lastUpdated:c,link:u,pubDate:h,title:l}=this;return!(!l&&!n)&&(e&&e.forEach((t=>this.feed.addCategory(t.name))),a&&a.forEach((t=>this.feed.addContributor(t))),{title:l,link:u,description:n,author:t,category:e,enclosure:i,guid:s,pubDate:h,lastUpdated:c,content:r,image:p,contributor:a,copyright:o})}}class y{pages;options;app;feed;constructor(t,e,r,a){this.pages=t,this.options=e,this.app=a,this.feed=new m(r)}addPages(){let t=0;const r=this.pages.slice(0,this.options.count);for(const e of r){const r=new f(e,this.feed,this.options,this.app).getFeedItem();r&&(this.feed.addItem(r),t+=1)}n.success(`added ${e.cyan(`${t} page(s)`)} as feed item(s)`)}async generateFeed(){const{dest:t}=this.app.dir,a=c(this.options.output);if(this.addPages(),n.load("Generating Feed"),a.atom.enable){const o=t(a.atom.path);await r.outputFile(o,this.feed.atom()),n.update(`Atom feed file generated and saved to ${e.cyan(a.atom.path)}`),n.success(),n.load("Generating Feed")}if(a.json.enable){const o=t(a.json.path);await r.outputFile(o,this.feed.json()),n.update(`JSON feed file generated and saved to ${e.cyan(a.json.path)}`),n.success(),n.load("Generating Feed")}if(a.rss.enable){const o=t(a.rss.path);await r.outputFile(o,this.feed.rss()),n.update(`RSS feed file generated and saved to ${e.cyan(a.rss.path)}`),n.success()}}}exports.default=(e,r)=>{const a=((e,r)=>{const{themeConfig:a}=r.options,o=e.hostname||a.hostname;return o?(e.hostname=o.replace(/\/?$/u,""),e.rootLang=t.getRootLang(r),e):(n.error("Option 'hostname' is required!"),!1)})(e,r);if(!a)return{};const o=((e,r)=>{const{rootLang:a,hostname:o,icon:n,image:i}=e,{base:p,themeConfig:c}=r.options,{title:u,description:h}=r.siteData,l=e.channel?.author?.name||c.author,d=c?.footer?.copyright||(l?`Copyright by ${l}`:""),g={title:u,link:s(o,p),description:h,language:a,copyright:d,pubDate:new Date,lastUpdated:new Date,...n?{icon:n}:{},...i?{image:i}:{},...l?{author:{name:l}}:{}};return t.deepAssign(g,e.channel||{})})(a,r),i=c(a.output),p=((t,e,r)=>{const{base:a}=r.options,{hostname:o}=t;return{atom:s(o,a,e.atom.path),json:s(o,a,e.json.path),rss:s(o,a,e.rss.path)}})(a,i,r),u=[];return{name:"feed2",extendsPageData(t){var e;a.filter&&("function"!=typeof a.filter||!a.filter(t)||((e=t.frontmatter).home||!1===e.article||e.feed&&!1===e.feed.enable))||u.push(t)},onPrepared(){((t,e)=>{const r=c(t.output),{base:a}=e.options,{siteData:o}=e,n=(e,r,n)=>["link",{rel:"alternate",type:n,href:s(t.hostname,a,r),title:`${o.title||""} ${e} Feed`}];o.head||(o.head=[]),r.atom.enable&&o.head.push(n("Atom",r.atom.path,"application/atom+xml")),r.json.enable&&o.head.push(n("JSON",r.json.path,"application/json")),r.rss.enable&&o.head.push(n("RSS",r.rss.path,"application/rss+xml"))})(a,r)},async onGenerated(){const t=("function"==typeof a.sort?u.sort(a.sort):u).slice(0,a.count);await new y(t,a,{channel:o,links:p},r).generateFeed()}}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@mr-hope/vuepress-shared"),e=require("@vuepress/utils");function r(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,a.get?a:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var a=r(require("xml-js"));const o=new t.Logger("Feed"),n=t=>t.replace(/ class=".*?"/gu,"").replace(/ v-pre/gu,"").replace(/<a href="#.*?">.*?<\/a>/gu,"").replace(/(<!--.*?-->)|(<!--[\S\s]+?-->)|(<!--[\S\s]*?$)/gu,"").replace(/<OutboundLink ?\/>/gu,"").replace(/<RouterLink to="(.*?)">(.*?)<\/RouterLink>/gu,'<a href="$1">$2</a>').replace(/<(?:a|div|span)[^>]*?\/>/gu,"").replace(/<(Badge|FlowChart|Presentation).*?(?:>.*?<\/\1>|\/>)/gu,"<i>Content not supported</i>").replace(/<math[\s\S]*?\/math>/gu,"<i>Content not supported</i>"),i=(t,e="",r="")=>`${t}${e.replace(/^\/?/u,"/").replace(/\/?$/u,"/")}${r.replace(/^\//u,"")}`,s=(t="")=>`image/${"jpg"===t?"jpeg":"svg"===t?"svg+xml":"jpeg"===t||"png"===t||"bmp"===t||"gif"===t||"webp"===t?t:""}`,c=e=>t.deepAssign({atom:{enable:!0,path:"atom.xml"},json:{enable:!0,path:"feed.json"},rss:{enable:!0,path:"rss.xml"}},e||{}),p=e=>{const{name:r,email:a,url:o}=e;return{name:r,...a?{email:a}:{},...o?{uri:t.encodeXML(o)}:{}}},u=t=>{const{name:e,scheme:r}=t;return{_attributes:{term:e,scheme:r}}},h=t=>({name:t.name,...t.url?{url:t.url}:{},...t.avator?{avator:t.avator}:{}}),l=t=>{const{name:e,domain:r}=t;return{_text:e,...r?{_attributes:{domain:r}}:{}}},d=e=>{const r=e.guid||t.encodeXML(e.link);return{...t.isUrl(r)?{}:{_attributes:{isPermaLink:!1}},_text:r}};class g{options;items=[];categories=new Set;_contributorKeys=new Set;contributors=[];constructor(t){this.options=t}addItem=t=>{this.items.push(t)};addCategory=t=>{this.categories.add(t)};addContributor=t=>{const e=t.email||t.name;e&&!this._contributorKeys.has(e)&&(this._contributorKeys.add(e),this.contributors.push(t))};atom=()=>(e=>{const{channel:r,links:o}=e.options,n={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}},feed:{_attributes:{xmlns:"http://www.w3.org/2005/Atom",...r.language?{"xml:lang":r.language}:{}},id:r.link,title:r.title,...r.description?{subtitle:r.description}:{},...r.author?{author:p(r.author)}:{},updated:r.lastUpdated?r.lastUpdated.toISOString():(new Date).toISOString(),generator:"vuepress-plugin-feed2",link:[{_attributes:{rel:"self",href:t.encodeXML(o.atom)}}]}};return r.link&&n.feed.link.push({_attributes:{rel:"alternate",href:t.encodeXML(r.link)}}),r.hub&&n.feed.link.push({_attributes:{rel:"hub",href:t.encodeXML(r.hub)}}),r.image&&(n.feed.logo=r.image),r.icon&&(n.feed.icon=r.icon),r.copyright&&(n.feed.rights=r.copyright),n.feed.category=Array.from(e.categories).map((t=>({_attributes:{term:t}}))),n.feed.contributor=Array.from(e.contributors).filter((t=>t.name)).map((t=>p(t))),n.feed.entry=e.items.map((e=>{const r={title:{_attributes:{type:"html"},_text:t.encodeXML(e.title)},id:t.encodeXML(e.guid||e.link),link:{_attributes:{href:t.encodeXML(e.link)}},updated:e.lastUpdated.toISOString()};return e.description&&(r.summary={_attributes:{type:"html"},_cdata:t.encodeCDATA(e.description)}),e.content&&(r.content={_attributes:{type:"html"},_cdata:t.encodeCDATA(e.content)}),Array.isArray(e.author)?r.author=e.author.filter((t=>t.name)).map((t=>p(t))):e.author&&e.author.name&&(r.author=[p(e.author)]),Array.isArray(e.category)?r.category=e.category.map((t=>u(t))):e.category&&(r.category=[u(e.category)]),Array.isArray(e.contributor)&&(r.contributor=e.contributor.map((t=>p(t)))),e.pubDate&&(r.published=e.pubDate.toISOString()),e.copyright&&(r.rights=e.copyright),r})),a.js2xml(n,{compact:!0,ignoreComment:!0,spaces:2})})(this);rss=()=>(e=>{const{links:r,channel:o}=e.options;let n=!1;const i={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}},rss:{_attributes:{version:"2.0","xmlns:atom":"http://www.w3.org/2005/Atom"},channel:{"atom:link":{_attributes:{href:r.rss,rel:"self",type:"application/rss+xml"}},title:{_text:o.title},link:{_text:t.encodeXML(o.link)},description:{_text:o.description},language:{_text:t.encodeXML(o.language)},pubDate:{_text:o.pubDate?o.pubDate.toUTCString():(new Date).toUTCString()},lastBuildDate:{_text:o.lastUpdated?o.lastUpdated.toUTCString():(new Date).toUTCString()},generator:{_text:"vuepress-plugin-feed2"},docs:{_text:"https://validator.w3.org/feed/docs/rss2.html"}}}};return o.copyright&&(i.rss.channel.copyright={_text:o.copyright}),o.ttl&&(i.rss.channel.ttl={_text:o.ttl.toString()}),o.image&&(i.rss.channel.image={title:{_text:o.title},url:{_text:o.image},link:{_text:t.encodeXML(o.link)}}),i.rss.channel.category=Array.from(e.categories).map((t=>({_text:t}))),i.rss.channel.item=e.items.map((e=>{const a={title:{_text:t.encodeXML(e.title)},link:{_text:t.encodeXML(e.link)},guid:d(e),source:{_attributes:{url:r.rss},_text:e.title}};if(e.description&&(a.description={_text:t.encodeXML(e.description)}),Array.isArray(e.author)){const t=e.author.find((t=>t.email&&t.name));t&&(a.author={_text:`${t.email} (${t.name})`})}else if("object"==typeof e.author){const{name:t,email:r}=e.author;r&&t&&(a.author={_text:`${r} (${t})`})}var o;return Array.isArray(e.category)?a.category=e.category.filter((t=>t.name)).map((t=>l(t))):"object"==typeof e.category&&e.category.name&&(a.category=[l(e.category)]),e.comments&&(a.comments={_text:t.encodeXML(e.link)}),e.pubDate&&(a.pubDate={_text:e.pubDate.toUTCString()}),e.content&&(n=!0,a["content:encoded"]={_cdata:t.encodeCDATA(e.content)}),e.enclosure&&(a.enclosure={_attributes:{url:(o=e.enclosure).url,...o.length?{length:o.length}:{},...o.type?{type:o.type}:{}}}),a})),n&&(i.rss._attributes["xmlns:content"]="http://purl.org/rss/1.0/modules/content/",i.rss._attributes["xmlns:dc"]="http://purl.org/dc/elements/1.1/"),a.js2xml(i,{compact:!0,ignoreComment:!0,spaces:2})})(this);json=()=>(t=>{const{channel:e,links:r}=t.options,a={version:"https://jsonfeed.org/version/1.1",title:e.title,home_page_url:e.link,feed_url:r.json};return e.description&&(a.description=e.description),e.image&&(a.icon=e.image),e.icon&&(a.favicon=e.icon),e.author?.name&&(a.author={name:e.author.name,...e.author.url?{url:e.author.url}:{},...e.author.avator?{avator:e.author.avator}:{}}),a.items=t.items.map((t=>{const e={title:t.title,url:t.link,id:t.guid||t.link,...t.description?{summary:t.description}:{},content_html:t.content};return t.image&&(e.image=t.image),t.pubDate&&(e.date_published=t.pubDate.toISOString()),t.lastUpdated&&(e.date_modified=t.lastUpdated.toISOString()),Array.isArray(t.author)?e.authors=t.author.filter((t=>t.name)).map((t=>h(t))):"object"==typeof t.author&&(e.authors=[h(t.author)]),Array.isArray(t.category)?e.tags=t.category.filter((t=>t.name)).map((t=>t.name)):t.category&&(e.tags=[t.category.name]),e})),JSON.stringify(a,null,2)})(this)}class m{page;feed;options;app;feedOption;frontmatter;base;themeConfig;constructor(t,e,r,a){this.page=t,this.feed=e,this.options=r,this.app=a,this.frontmatter=t.frontmatter,this.feedOption=this.frontmatter.feed||{},this.base=this.app.options.base,this.themeConfig=this.app.options.themeConfig}get title(){return this.feedOption.title||this.page.title}get link(){return i(this.options.hostname,this.base,this.page.path)}get description(){return this.feedOption.description?this.feedOption.description:this.frontmatter.description?this.frontmatter.description:this.page.excerpt?n(this.app.markdown.render(this.page.excerpt)):void 0}get author(){return Array.isArray(this.feedOption.author)?this.feedOption.author:"object"==typeof this.feedOption.author?[this.feedOption.author]:!1===this.frontmatter.author?[]:t.getAuthor(this.frontmatter,this.themeConfig).map((t=>({name:t})))}get category(){if(Array.isArray(this.feedOption.category))return this.feedOption.category;if("object"==typeof this.feedOption.category)return[this.feedOption.category];const{categories:e,category:r=e}=this.frontmatter;return t.getCategory(r).map((t=>({name:t})))}get enclosure(){if(this.image)return{url:this.image,type:s(this.image.split(".").pop())}}get guid(){return this.feedOption.guid||this.link}get pubDate(){const{time:t,date:e=t}=this.page.frontmatter,{createdTime:r}=this.page.git||{};return e&&e instanceof Date?e:r?new Date(r):void 0}get lastUpdated(){const{updatedTime:t}=this.page.git||{};return t?new Date(t):new Date}get content(){return this.feedOption.content?this.feedOption.content:n(this.page.contentRendered)}get image(){const{banner:e,cover:r}=this.frontmatter;if(e){if(t.isAbsoluteUrl(e))return i(this.options.hostname,this.app.options.base,e);if(t.isUrl(e))return e}if(r){if(t.isAbsoluteUrl(r))return i(this.options.hostname,this.app.options.base,r);if(t.isUrl(r))return r}const a=/!\[.*?\]\((.*?)\)/iu.exec(this.page.content);if(a){if(t.isAbsoluteUrl(a[1]))return i(this.options.hostname,this.app.options.base,a[1]);if(t.isUrl(a[1]))return a[1]}}get contributor(){return Array.isArray(this.feedOption.contributor)?this.feedOption.contributor:"object"==typeof this.feedOption.contributor?[this.feedOption.contributor]:this.author}get copyright(){if(this.frontmatter.copyrightText)return this.frontmatter.copyrightText;const t=this.author[0];return t&&t.name?`Copyright by ${t.name}`:void 0}getFeedItem(){const{author:t,category:e,content:r,contributor:a,copyright:o,description:n,enclosure:i,guid:s,image:c,lastUpdated:p,link:u,pubDate:h,title:l}=this;return!(!l&&!n)&&(e&&e.forEach((t=>this.feed.addCategory(t.name))),a&&a.forEach((t=>this.feed.addContributor(t))),{title:l,link:u,description:n,author:t,category:e,enclosure:i,guid:s,pubDate:h,lastUpdated:p,content:r,image:c,contributor:a,copyright:o})}}class f{pages;options;app;feed;constructor(t,e,r,a){this.pages=t,this.options=e,this.app=a,this.feed=new g(r)}addPages(){let t=0;const r=this.pages.slice(0,this.options.count);for(const e of r){const r=new m(e,this.feed,this.options,this.app).getFeedItem();r&&(this.feed.addItem(r),t+=1)}o.success(`added ${e.chalk.cyan(`${t} page(s)`)} as feed item(s)`)}async generateFeed(){const{dest:t}=this.app.dir,r=c(this.options.output);if(this.addPages(),o.load("Generating Feed"),r.atom.enable){const a=t(r.atom.path);await e.fs.outputFile(a,this.feed.atom()),o.update(`Atom feed file generated and saved to ${e.chalk.cyan(r.atom.path)}`),o.success(),o.load("Generating Feed")}if(r.json.enable){const a=t(r.json.path);await e.fs.outputFile(a,this.feed.json()),o.update(`JSON feed file generated and saved to ${e.chalk.cyan(r.json.path)}`),o.success(),o.load("Generating Feed")}if(r.rss.enable){const a=t(r.rss.path);await e.fs.outputFile(a,this.feed.rss()),o.update(`RSS feed file generated and saved to ${e.chalk.cyan(r.rss.path)}`),o.success()}}}exports.default=(e,r)=>{const a=((e,r)=>{const{themeConfig:a}=r.options,n=e.hostname||a.hostname;return n?(e.hostname=n.replace(/\/?$/u,""),e.rootLang=t.getRootLang(r),e):(o.error("Option 'hostname' is required!"),!1)})(e,r);if(!a)return{};const n=((e,r)=>{const{rootLang:a,hostname:o,icon:n,image:s}=e,{base:c,themeConfig:p}=r.options,{title:u,description:h}=r.siteData,l=e.channel?.author?.name||p.author,d=p?.footer?.copyright||(l?`Copyright by ${l}`:""),g={title:u,link:i(o,c),description:h,language:a,copyright:d,pubDate:new Date,lastUpdated:new Date,...n?{icon:n}:{},...s?{image:s}:{},...l?{author:{name:l}}:{}};return t.deepAssign(g,e.channel||{})})(a,r),s=c(a.output),p=((t,e,r)=>{const{base:a}=r.options,{hostname:o}=t;return{atom:i(o,a,e.atom.path),json:i(o,a,e.json.path),rss:i(o,a,e.rss.path)}})(a,s,r);return{name:"feed2",onPrepared(){((t,e)=>{const r=c(t.output),{base:a}=e.options,{siteData:o}=e,n=(e,r,n)=>["link",{rel:"alternate",type:n,href:i(t.hostname,a,r),title:`${o.title||""} ${e} Feed`}];o.head||(o.head=[]),r.atom.enable&&o.head.push(n("Atom",r.atom.path,"application/atom+xml")),r.json.enable&&o.head.push(n("JSON",r.json.path,"application/json")),r.rss.enable&&o.head.push(n("RSS",r.rss.path,"application/rss+xml"))})(a,r)},async onGenerated(t){const e=t.pages.filter((t=>{return!a.filter||"function"==typeof a.filter&&a.filter(t)&&!((e=t.frontmatter).home||!1===e.article||e.feed&&!1===e.feed.enable);var e})).sort(a.sort).slice(0,a.count);await new f(e,a,{channel:n,links:p},t).generateFeed()}}};
//# sourceMappingURL=index.js.map
{
"name": "vuepress-plugin-feed2",
"version": "2.0.0-alpha.5",
"version": "2.0.0-alpha.6",
"description": "Feed plugin for vuepress-theme-hope",

@@ -43,6 +43,3 @@ "keywords": [

"dependencies": {
"@mr-hope/vuepress-shared": "2.0.0-alpha.5",
"@types/fs-extra": "^9.0.11",
"chalk": "^4.1.1",
"fs-extra": "^10.0.0",
"@mr-hope/vuepress-shared": "2.0.0-alpha.6",
"xml-js": "^1.6.11"

@@ -53,3 +50,3 @@ },

},
"gitHead": "4e4fb1c3d529c25913738550b9c74d574022a541"
"gitHead": "a3bbd5850499d6708af92d189f4503d0c1d8d4a8"
}

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