vuepress-plugin-feed2
Advanced tools
Comparing version 2.0.0-beta.5 to 2.0.0-beta.6
@@ -389,3 +389,3 @@ import { Page, Plugin, PluginConfig } from '@vuepress/core'; | ||
* | ||
* @default 1000 | ||
* @default 100 | ||
*/ | ||
@@ -392,0 +392,0 @@ count?: number; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@mr-hope/vuepress-shared"),e=require("@vuepress/utils"),r=require("xml-js");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var a=i(r);const n=new t.Logger("vuepress-plugin-feed2"),o=(t,e)=>t&&t instanceof Date?e&&e instanceof Date?e.getTime()-t.getTime():-1:1,s=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>"),u=(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=t=>({atomOutputFilename:t.atomOutputFilename||"atom.xml",jsonOutputFilename:t.jsonOutputFilename||"feed.json",rssOutputFilename:t.rssOutputFilename||"rss.xml"}),h=(t,e)=>{const{base:r}=t.options,{hostname:i}=e,{atomOutputFilename:a,jsonOutputFilename:n,rssOutputFilename:o}=c(e);return{atom:u(i,r,a),json:u(i,r,n),rss:u(i,r,o)}},g=e=>{const{name:r,email:i,url:a}=e;return{name:r,...i?{email:i}:{},...a?{uri:t.encodeXML(a)}:{}}},l=t=>{const{name:e,scheme:r}=t;return{_attributes:{term:e,scheme:r}}},d=t=>({name:t.name,...t.url?{url:t.url}:{},...t.avatar?{avatar:t.avatar}:{}}),m=t=>{const{name:e,domain:r}=t;return{_text:e,...r?{_attributes:{domain:r}}:{}}},f=e=>{const r=e.guid||t.encodeXML(e.link);return{...t.isUrl(r)?{}:{_attributes:{isPermaLink:!1}},_text:r}};class y{constructor(e){this.options=e,this.items=[],this.categories=new Set,this._contributorKeys=new Set,this.contributors=[],this.addItem=t=>{this.items.push(t)},this.addCategory=t=>{this.categories.add(t)},this.addContributor=t=>{const e=t.email||t.name;e&&!this._contributorKeys.has(e)&&(this._contributorKeys.add(e),this.contributors.push(t))},this.atom=()=>(e=>{const{channel:i,links:a}=e.options,n={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}},feed:{_attributes:{xmlns:"http://www.w3.org/2005/Atom",...i.language?{"xml:lang":i.language}:{}},id:i.link,title:i.title,...i.description?{subtitle:i.description}:{},...i.author?{author:g(i.author)}:{},updated:i.lastUpdated?i.lastUpdated.toISOString():(new Date).toISOString(),generator:"vuepress-plugin-feed2",link:[{_attributes:{rel:"self",href:t.encodeXML(a.atom)}}]}};return i.link&&n.feed.link.push({_attributes:{rel:"alternate",href:t.encodeXML(i.link)}}),i.hub&&n.feed.link.push({_attributes:{rel:"hub",href:t.encodeXML(i.hub)}}),i.image&&(n.feed.logo=i.image),i.icon&&(n.feed.icon=i.icon),i.copyright&&(n.feed.rights=i.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=>g(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=>g(t))):e.author&&e.author.name&&(r.author=[g(e.author)]),Array.isArray(e.category)?r.category=e.category.map((t=>l(t))):e.category&&(r.category=[l(e.category)]),Array.isArray(e.contributor)&&(r.contributor=e.contributor.map((t=>g(t)))),e.pubDate&&(r.published=e.pubDate.toISOString()),e.copyright&&(r.rights=e.copyright),r})),r.js2xml(n,{compact:!0,ignoreComment:!0,spaces:2})})(this),this.rss=()=>(e=>{const{links:r,channel:i}=e.options;let n=!1;const o={_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:i.title},link:{_text:t.encodeXML(i.link)},description:{_text:i.description},language:{_text:t.encodeXML(i.language)},pubDate:{_text:i.pubDate?i.pubDate.toUTCString():(new Date).toUTCString()},lastBuildDate:{_text:i.lastUpdated?i.lastUpdated.toUTCString():(new Date).toUTCString()},generator:{_text:"vuepress-plugin-feed2"},docs:{_text:"https://validator.w3.org/feed/docs/rss2.html"}}}};return i.copyright&&(o.rss.channel.copyright={_text:i.copyright}),i.ttl&&(o.rss.channel.ttl={_text:i.ttl.toString()}),i.image&&(o.rss.channel.image={title:{_text:i.title},url:{_text:i.image},link:{_text:t.encodeXML(i.link)}}),o.rss.channel.category=Array.from(e.categories).map((t=>({_text:t}))),o.rss.channel.item=e.items.map((e=>{const i={title:{_text:t.encodeXML(e.title)},link:{_text:t.encodeXML(e.link)},guid:f(e),source:{_attributes:{url:r.rss},_text:e.title}};if(e.description&&(i.description={_text:t.encodeXML(e.description)}),Array.isArray(e.author)){const t=e.author.find((t=>t.email&&t.name));t&&(i.author={_text:`${t.email} (${t.name})`})}else if("object"==typeof e.author){const{name:t,email:r}=e.author;r&&t&&(i.author={_text:`${r} (${t})`})}var a;return Array.isArray(e.category)?i.category=e.category.filter((t=>t.name)).map((t=>m(t))):"object"==typeof e.category&&e.category.name&&(i.category=[m(e.category)]),e.comments&&(i.comments={_text:t.encodeXML(e.link)}),e.pubDate&&(i.pubDate={_text:e.pubDate.toUTCString()}),e.content&&(n=!0,i["content:encoded"]={_cdata:t.encodeCDATA(e.content)}),e.enclosure&&(i.enclosure={_attributes:{url:(a=e.enclosure).url,...a.length?{length:a.length}:{},...a.type?{type:a.type}:{}}}),i})),n&&(o.rss._attributes["xmlns:content"]="http://purl.org/rss/1.0/modules/content/",o.rss._attributes["xmlns:dc"]="http://purl.org/dc/elements/1.1/"),a.js2xml(o,{compact:!0,ignoreComment:!0,spaces:2})})(this),this.json=()=>(t=>{const{channel:e,links:r}=t.options,i={version:"https://jsonfeed.org/version/1.1",title:e.title,home_page_url:e.link,feed_url:r.json};return e.description&&(i.description=e.description),e.image&&(i.icon=e.image),e.icon&&(i.favicon=e.icon),e.author?.name&&(i.author={name:e.author.name,...e.author.url?{url:e.author.url}:{},...e.author.avatar?{avatar:e.author.avatar}:{}}),i.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=>d(t))):"object"==typeof t.author&&(e.authors=[d(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(i,null,2)})(this)}}class b{constructor(t,e,r,i){this.app=t,this.options=e,this.page=r,this.feed=i,this.base=this.app.options.base,this.frontmatter=r.frontmatter,this.getter=e.getter||{},this.pageFeedOptions=this.frontmatter.feed||{}}get title(){return"function"==typeof this.getter.title?this.getter.title(this.page):this.pageFeedOptions.title||this.page.title}get link(){return"function"==typeof this.getter.link?this.getter.link(this.page):u(this.options.hostname,this.base,this.page.path)}get description(){return"function"==typeof this.getter.description?this.getter.description(this.page):this.pageFeedOptions.description?this.pageFeedOptions.description:this.frontmatter.description?this.frontmatter.description:this.page.excerpt?s(this.app.markdown.render(this.page.excerpt)):void 0}get author(){return"function"==typeof this.getter.author?this.getter.author(this.page):Array.isArray(this.pageFeedOptions.author)?this.pageFeedOptions.author:"object"==typeof this.pageFeedOptions.author?[this.pageFeedOptions.author]:!1===this.frontmatter.author?[]:this.frontmatter.author?t.getAuthor(this.frontmatter.author):this.options.channel?.author?t.getAuthor(this.options.channel?.author):[]}get category(){if("function"==typeof this.getter.category)return this.getter.category(this.page);if(Array.isArray(this.pageFeedOptions.category))return this.pageFeedOptions.category;if("object"==typeof this.pageFeedOptions.category)return[this.pageFeedOptions.category];const{categories:e,category:r=e}=this.frontmatter;return t.getCategory(r).map((t=>({name:t})))}get enclosure(){return"function"==typeof this.getter.enclosure?this.getter.enclosure(this.page):this.image?{url:this.image,type:p(this.image.split(".").pop())}:void 0}get guid(){return this.pageFeedOptions.guid||this.link}get pubDate(){if("function"==typeof this.getter.publishDate)return this.getter.publishDate(this.page);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(){if("function"==typeof this.getter.lastUpdateDate)return this.getter.lastUpdateDate(this.page);const{updatedTime:t}=this.page.git||{};return t?new Date(t):new Date}get content(){return"function"==typeof this.getter.content?this.getter.content(this.page):this.pageFeedOptions.content?this.pageFeedOptions.content:s(this.page.contentRendered)}get image(){if("function"==typeof this.getter.image)return this.getter.image(this.page);const{banner:e,cover:r}=this.frontmatter;if(e){if(t.isAbsoluteUrl(e))return u(this.options.hostname,this.app.options.base,e);if(t.isUrl(e))return e}if(r){if(t.isAbsoluteUrl(r))return u(this.options.hostname,this.app.options.base,r);if(t.isUrl(r))return r}const i=/!\[.*?\]\((.*?)\)/iu.exec(this.page.content);if(i){if(t.isAbsoluteUrl(i[1]))return u(this.options.hostname,this.app.options.base,i[1]);if(t.isUrl(i[1]))return i[1]}}get contributor(){return"function"==typeof this.getter.contributor?this.getter.contributor(this.page):Array.isArray(this.pageFeedOptions.contributor)?this.pageFeedOptions.contributor:"object"==typeof this.pageFeedOptions.contributor?[this.pageFeedOptions.contributor]:this.author}get copyright(){if("function"==typeof this.getter.copyright)return this.getter.copyright(this.page);if(this.frontmatter.copyright)return this.frontmatter.copyright;const t=this.author[0];return t&&t.name?`Copyright by ${t.name}`:void 0}getFeedItem(){const{author:t,category:e,content:r,contributor:i,copyright:a,description:n,enclosure:o,guid:s,image:u,lastUpdated:p,link:c,pubDate:h,title:g}=this;return g||n?(e&&e.forEach((t=>this.feed.addCategory(t.name))),i&&i.forEach((t=>this.feed.addContributor(t))),{title:g,link:c,description:n,author:t,category:e,enclosure:o,guid:s,pubDate:h,lastUpdated:p,content:r,image:u,contributor:i,copyright:a}):null}}class _{constructor(t,e,r,i){this.app=t,this.options=e,this.pages=r,this.feed=new y(i)}addPages(){let t=0;for(const e of this.pages){const r=new b(this.app,this.options,e,this.feed).getFeedItem();r&&(this.feed.addItem(r),t+=1)}n.succeed(`added ${e.chalk.cyan(`${t} page(s)`)} as feed item(s)`)}async generateFeed(){const{dest:t}=this.app.dir,{atomOutputFilename:r,jsonOutputFilename:i,rssOutputFilename:a}=c(this.options);this.addPages(),this.options.atom&&(n.load("Generating Atom Feed"),await e.fs.outputFile(t(r),this.feed.atom()),n.update(`Atom feed file generated and saved to ${e.chalk.cyan(r)}`),n.succeed()),this.options.json&&(n.load("Generating JSON Feed"),await e.fs.outputFile(t(i),this.feed.json()),n.update(`JSON feed file generated and saved to ${e.chalk.cyan(i)}`),n.succeed()),this.options.rss&&(n.load("Generating RSS Feed"),await e.fs.outputFile(t(a),this.feed.rss()),n.update(`RSS feed file generated and saved to ${e.chalk.cyan(a)}`),n.succeed())}}const O=(e,r)=>{if(!e.hostname)return n.error("Option 'hostname' is required!"),{name:"vuepress-plugin-feed2"};e.hostname=e.hostname.replace(/\/?$/u,"");const i=e,a=((e,r)=>{const{hostname:i,icon:a,image:n}=r,{base:o}=e.options,{title:s,description:p}=e.siteData,c=r.channel?.author?.name,h={title:s,link:u(i,o),description:p,language:t.getRootLang(e),copyright:c?`Copyright by ${c}`:"",pubDate:new Date,lastUpdated:new Date,...a?{icon:a}:{},...n?{image:n}:{},...c?{author:{name:c}}:{}};return t.deepAssign(h,r.channel||{})})(r,i);return i.atom||i.json||i.rss?{name:"vuepress-plugin-feed2",onPrepared:t=>((t,e)=>{const{base:r}=t.options,{siteData:i}=t,{atomOutputFilename:a,jsonOutputFilename:n,rssOutputFilename:o}=c(e),s=(t,a,n)=>["link",{rel:"alternate",type:n,href:u(e.hostname,r,a),title:`${i.title||""} ${t} Feed`}];i.head||(i.head=[]),e.atom&&i.head.push(s("Atom",a,"application/atom+xml")),e.json&&i.head.push(s("JSON",n,"application/json")),e.rss&&i.head.push(s("RSS",o,"application/rss+xml"))})(t,i),onGenerated:async t=>{const{filter:e=(({frontmatter:t,filePathRelative:e})=>!(t.home||!e||!1===t.article||!1===t.feed)),sorter:r=((t,e)=>o(t.git?.createdTime?new Date(t.git?.createdTime):t.frontmatter.date,e.git?.createdTime?new Date(e.git?.createdTime):e.frontmatter.date))}=i,n=t.pages.filter(e).sort(r).slice(0,i.count||1e3);await new _(t,i,n,{channel:a,links:h(t,i)}).generateFeed()}}:(n.info("No requested output, the plugin won't start!"),{name:"vuepress-plugin-feed2"})};exports.default=O,exports.feed=t=>["feed2",t],exports.feedPlugin=O; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@mr-hope/vuepress-shared"),e=require("@vuepress/utils"),i=require("path"),r=require("xml-js");function a(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,r.get?r:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=a(r);const o=new t.Logger("vuepress-plugin-feed2"),s=(t,e)=>t&&t instanceof Date?e&&e instanceof Date?e.getTime()-t.getTime():-1:1,u=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>"),p=(t,e="",i="")=>`${t}${e.replace(/^\/?/u,"/").replace(/\/?$/u,"/")}${i.replace(/^\//u,"")}`,c=(t="")=>`image/${"jpg"===t?"jpeg":"svg"===t?"svg+xml":"jpeg"===t||"png"===t||"bmp"===t||"gif"===t||"webp"===t?t:""}`,h=t=>({atomOutputFilename:t.atomOutputFilename||"atom.xml",jsonOutputFilename:t.jsonOutputFilename||"feed.json",rssOutputFilename:t.rssOutputFilename||"rss.xml"}),l=(t,e)=>{const{base:i}=t.options,{hostname:r}=e,{atomOutputFilename:a,jsonOutputFilename:n,rssOutputFilename:o}=h(e);return{atom:p(r,i,a),json:p(r,i,n),rss:p(r,i,o)}},d=e=>{const{name:i,email:r,url:a}=e;return{name:i,...r?{email:r}:{},...a?{uri:t.encodeXML(a)}:{}}},g=t=>{const{name:e,scheme:i}=t;return{_attributes:{term:e,scheme:i}}},m=t=>({name:t.name,...t.url?{url:t.url}:{},...t.avatar?{avatar:t.avatar}:{}}),f=t=>{const{name:e,domain:i}=t;return{_text:e,...i?{_attributes:{domain:i}}:{}}},y=e=>{const i=e.guid||t.encodeXML(e.link);return{...t.isUrl(i)?{}:{_attributes:{isPermaLink:!1}},_text:i}};class b{constructor(e){this.options=e,this.items=[],this.categories=new Set,this._contributorKeys=new Set,this.contributors=[],this.addItem=t=>{this.items.push(t)},this.addCategory=t=>{this.categories.add(t)},this.addContributor=t=>{const e=t.email||t.name;e&&!this._contributorKeys.has(e)&&(this._contributorKeys.add(e),this.contributors.push(t))},this.atom=()=>(e=>{const{channel:i,links:a}=e.options,n={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}},feed:{_attributes:{xmlns:"http://www.w3.org/2005/Atom",...i.language?{"xml:lang":i.language}:{}},id:i.link,title:i.title,...i.description?{subtitle:i.description}:{},...i.author?{author:d(i.author)}:{},updated:i.lastUpdated?i.lastUpdated.toISOString():(new Date).toISOString(),generator:"vuepress-plugin-feed2",link:[{_attributes:{rel:"self",href:t.encodeXML(a.atom)}}]}};return i.link&&n.feed.link.push({_attributes:{rel:"alternate",href:t.encodeXML(i.link)}}),i.hub&&n.feed.link.push({_attributes:{rel:"hub",href:t.encodeXML(i.hub)}}),i.image&&(n.feed.logo=i.image),i.icon&&(n.feed.icon=i.icon),i.copyright&&(n.feed.rights=i.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=>d(t))),n.feed.entry=e.items.map((e=>{const i={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&&(i.summary={_attributes:{type:"html"},_cdata:t.encodeCDATA(e.description)}),e.content&&(i.content={_attributes:{type:"html"},_cdata:t.encodeCDATA(e.content)}),Array.isArray(e.author)?i.author=e.author.filter((t=>t.name)).map((t=>d(t))):e.author&&e.author.name&&(i.author=[d(e.author)]),Array.isArray(e.category)?i.category=e.category.map((t=>g(t))):e.category&&(i.category=[g(e.category)]),Array.isArray(e.contributor)&&(i.contributor=e.contributor.map((t=>d(t)))),e.pubDate&&(i.published=e.pubDate.toISOString()),e.copyright&&(i.rights=e.copyright),i})),r.js2xml(n,{compact:!0,ignoreComment:!0,spaces:2})})(this),this.rss=()=>(e=>{const{links:i,channel:r}=e.options;let a=!1;const o={_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:i.rss,rel:"self",type:"application/rss+xml"}},title:{_text:r.title},link:{_text:t.encodeXML(r.link)},description:{_text:r.description},language:{_text:t.encodeXML(r.language)},pubDate:{_text:r.pubDate?r.pubDate.toUTCString():(new Date).toUTCString()},lastBuildDate:{_text:r.lastUpdated?r.lastUpdated.toUTCString():(new Date).toUTCString()},generator:{_text:"vuepress-plugin-feed2"},docs:{_text:"https://validator.w3.org/feed/docs/rss2.html"}}}};return r.copyright&&(o.rss.channel.copyright={_text:r.copyright}),r.ttl&&(o.rss.channel.ttl={_text:r.ttl.toString()}),r.image&&(o.rss.channel.image={title:{_text:r.title},url:{_text:r.image},link:{_text:t.encodeXML(r.link)}}),o.rss.channel.category=Array.from(e.categories).map((t=>({_text:t}))),o.rss.channel.item=e.items.map((e=>{const r={title:{_text:t.encodeXML(e.title)},link:{_text:t.encodeXML(e.link)},guid:y(e),source:{_attributes:{url:i.rss},_text:e.title}};if(e.description&&(r.description={_text:t.encodeXML(e.description)}),Array.isArray(e.author)){const t=e.author.find((t=>t.email&&t.name));t&&(r.author={_text:`${t.email} (${t.name})`})}else if("object"==typeof e.author){const{name:t,email:i}=e.author;i&&t&&(r.author={_text:`${i} (${t})`})}var n;return Array.isArray(e.category)?r.category=e.category.filter((t=>t.name)).map((t=>f(t))):"object"==typeof e.category&&e.category.name&&(r.category=[f(e.category)]),e.comments&&(r.comments={_text:t.encodeXML(e.link)}),e.pubDate&&(r.pubDate={_text:e.pubDate.toUTCString()}),e.content&&(a=!0,r["content:encoded"]={_cdata:t.encodeCDATA(e.content)}),e.enclosure&&(r.enclosure={_attributes:{url:(n=e.enclosure).url,...n.length?{length:n.length}:{},...n.type?{type:n.type}:{}}}),r})),a&&(o.rss._attributes["xmlns:content"]="http://purl.org/rss/1.0/modules/content/",o.rss._attributes["xmlns:dc"]="http://purl.org/dc/elements/1.1/"),n.js2xml(o,{compact:!0,ignoreComment:!0,spaces:2})})(this),this.json=()=>(t=>{var e;const{channel:i,links:r}=t.options,a={version:"https://jsonfeed.org/version/1.1",title:i.title,home_page_url:i.link,feed_url:r.json};return i.description&&(a.description=i.description),i.image&&(a.icon=i.image),i.icon&&(a.favicon=i.icon),(null===(e=i.author)||void 0===e?void 0:e.name)&&(a.author={name:i.author.name,...i.author.url?{url:i.author.url}:{},...i.author.avatar?{avatar:i.author.avatar}:{}}),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=>m(t))):"object"==typeof t.author&&(e.authors=[m(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 _{constructor(t,e,i,r){this.app=t,this.options=e,this.page=i,this.feed=r,this.base=this.app.options.base,this.frontmatter=i.frontmatter,this.getter=e.getter||{},this.pageFeedOptions=this.frontmatter.feed||{}}get title(){return"function"==typeof this.getter.title?this.getter.title(this.page):this.pageFeedOptions.title||this.page.title}get link(){return"function"==typeof this.getter.link?this.getter.link(this.page):p(this.options.hostname,this.base,this.page.path)}get description(){return"function"==typeof this.getter.description?this.getter.description(this.page):this.pageFeedOptions.description?this.pageFeedOptions.description:this.frontmatter.description?this.frontmatter.description:this.page.excerpt?u(this.app.markdown.render(this.page.excerpt)):void 0}get author(){var e,i;return"function"==typeof this.getter.author?this.getter.author(this.page):Array.isArray(this.pageFeedOptions.author)?this.pageFeedOptions.author:"object"==typeof this.pageFeedOptions.author?[this.pageFeedOptions.author]:!1===this.frontmatter.author?[]:this.frontmatter.author?t.getAuthor(this.frontmatter.author):(null===(e=this.options.channel)||void 0===e?void 0:e.author)?t.getAuthor(null===(i=this.options.channel)||void 0===i?void 0:i.author):[]}get category(){if("function"==typeof this.getter.category)return this.getter.category(this.page);if(Array.isArray(this.pageFeedOptions.category))return this.pageFeedOptions.category;if("object"==typeof this.pageFeedOptions.category)return[this.pageFeedOptions.category];const{categories:e,category:i=e}=this.frontmatter;return t.getCategory(i).map((t=>({name:t})))}get enclosure(){return"function"==typeof this.getter.enclosure?this.getter.enclosure(this.page):this.image?{url:this.image,type:c(this.image.split(".").pop())}:void 0}get guid(){return this.pageFeedOptions.guid||this.link}get pubDate(){if("function"==typeof this.getter.publishDate)return this.getter.publishDate(this.page);const{time:t,date:e=t}=this.page.frontmatter,{createdTime:i}=this.page.git||{};return e&&e instanceof Date?e:i?new Date(i):void 0}get lastUpdated(){if("function"==typeof this.getter.lastUpdateDate)return this.getter.lastUpdateDate(this.page);const{updatedTime:t}=this.page.git||{};return t?new Date(t):new Date}get content(){return"function"==typeof this.getter.content?this.getter.content(this.page):this.pageFeedOptions.content?this.pageFeedOptions.content:u(this.page.contentRendered)}get image(){if("function"==typeof this.getter.image)return this.getter.image(this.page);const{banner:e,cover:i}=this.frontmatter;if(e){if(t.isAbsoluteUrl(e))return p(this.options.hostname,this.app.options.base,e);if(t.isUrl(e))return e}if(i){if(t.isAbsoluteUrl(i))return p(this.options.hostname,this.app.options.base,i);if(t.isUrl(i))return i}const r=/!\[.*?\]\((.*?)\)/iu.exec(this.page.content);if(r){if(t.isAbsoluteUrl(r[1]))return p(this.options.hostname,this.app.options.base,r[1]);if(t.isUrl(r[1]))return r[1]}}get contributor(){return"function"==typeof this.getter.contributor?this.getter.contributor(this.page):Array.isArray(this.pageFeedOptions.contributor)?this.pageFeedOptions.contributor:"object"==typeof this.pageFeedOptions.contributor?[this.pageFeedOptions.contributor]:this.author}get copyright(){if("function"==typeof this.getter.copyright)return this.getter.copyright(this.page);if(this.frontmatter.copyright)return this.frontmatter.copyright;const t=this.author[0];return t&&t.name?`Copyright by ${t.name}`:void 0}getFeedItem(){const{author:t,category:e,content:i,contributor:r,copyright:a,description:n,enclosure:o,guid:s,image:u,lastUpdated:p,link:c,pubDate:h,title:l}=this;return l||n?(e&&e.forEach((t=>this.feed.addCategory(t.name))),r&&r.forEach((t=>this.feed.addContributor(t))),{title:l,link:c,description:n,author:t,category:e,enclosure:o,guid:s,pubDate:h,lastUpdated:p,content:i,image:u,contributor:r,copyright:a}):null}}class v{constructor(t,e,i,r){this.app=t,this.options=e,this.pages=i,this.feed=new b(r)}addPages(){let t=0;for(const e of this.pages){const i=new _(this.app,this.options,e,this.feed).getFeedItem();i&&(this.feed.addItem(i),t+=1)}o.succeed(`added ${e.chalk.cyan(`${t} page(s)`)} as feed item(s)`)}async generateFeed(){const{dest:t}=this.app.dir,{atomOutputFilename:r,jsonOutputFilename:a,rssOutputFilename:n}=h(this.options);this.addPages(),this.options.atom&&(o.load("Generating Atom Feed"),await e.fs.ensureDir(i.dirname(t(r))),await e.fs.outputFile(t(r),this.feed.atom()),o.update(`Atom feed file generated and saved to ${e.chalk.cyan(r)}`),o.succeed()),this.options.json&&(o.load("Generating JSON Feed"),await e.fs.ensureDir(i.dirname(t(a))),await e.fs.outputFile(t(a),this.feed.json()),o.update(`JSON feed file generated and saved to ${e.chalk.cyan(a)}`),o.succeed()),this.options.rss&&(o.load("Generating RSS Feed"),await e.fs.ensureDir(i.dirname(t(n))),await e.fs.outputFile(t(n),this.feed.rss()),o.update(`RSS feed file generated and saved to ${e.chalk.cyan(n)}`),o.succeed())}}const O=(e,i)=>{if(!e.hostname)return o.error("Option 'hostname' is required!"),{name:"vuepress-plugin-feed2"};e.hostname=e.hostname.replace(/\/?$/u,"");const r=e,a=((e,i)=>{var r,a;const{hostname:n,icon:o,image:s}=i,{base:u}=e.options,{title:c,description:h}=e.siteData,l=null===(a=null===(r=i.channel)||void 0===r?void 0:r.author)||void 0===a?void 0:a.name,d={title:c,link:p(n,u),description:h,language:t.getRootLang(e),copyright:l?`Copyright by ${l}`:"",pubDate:new Date,lastUpdated:new Date,...o?{icon:o}:{},...s?{image:s}:{},...l?{author:{name:l}}:{}};return t.deepAssign(d,i.channel||{})})(i,r);return r.atom||r.json||r.rss?{name:"vuepress-plugin-feed2",onPrepared:t=>((t,e)=>{const{base:i}=t.options,{siteData:r}=t,{atomOutputFilename:a,jsonOutputFilename:n,rssOutputFilename:o}=h(e),s=(t,a,n)=>["link",{rel:"alternate",type:n,href:p(e.hostname,i,a),title:`${r.title||""} ${t} Feed`}];r.head||(r.head=[]),e.atom&&r.head.push(s("Atom",a,"application/atom+xml")),e.json&&r.head.push(s("JSON",n,"application/json")),e.rss&&r.head.push(s("RSS",o,"application/rss+xml"))})(t,r),onGenerated:async t=>{const{filter:e=(({frontmatter:t,filePathRelative:e})=>!(t.home||!e||!1===t.article||!1===t.feed)),sorter:i=((t,e)=>{var i,r,a,n;return s((null===(i=t.git)||void 0===i?void 0:i.createdTime)?new Date(null===(r=t.git)||void 0===r?void 0:r.createdTime):t.frontmatter.date,(null===(a=e.git)||void 0===a?void 0:a.createdTime)?new Date(null===(n=e.git)||void 0===n?void 0:n.createdTime):e.frontmatter.date)})}=r,n=t.pages.filter(e).sort(i).slice(0,r.count||100);await new v(t,r,n,{channel:a,links:l(t,r)}).generateFeed()}}:(o.info("No requested output, the plugin won't start!"),{name:"vuepress-plugin-feed2"})};exports.default=O,exports.feed=t=>["feed2",t],exports.feedPlugin=O; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "vuepress-plugin-feed2", | ||
"version": "2.0.0-beta.5", | ||
"version": "2.0.0-beta.6", | ||
"description": "Feed plugin for vuepress-theme-hope", | ||
@@ -44,3 +44,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@mr-hope/vuepress-shared": "2.0.0-beta.5", | ||
"@mr-hope/vuepress-shared": "2.0.0-beta.6", | ||
"@vuepress/utils": "2.0.0-beta.35", | ||
@@ -55,3 +55,3 @@ "xml-js": "^1.6.11" | ||
}, | ||
"gitHead": "a93fe4324f861311b1896478b934a9d394f196cf" | ||
"gitHead": "1fb0665939448756bb6a2db70d779da2402f5168" | ||
} |
import { chalk, fs } from "@vuepress/utils"; | ||
import { dirname } from "path"; | ||
import { Feed } from "./feed"; | ||
@@ -53,2 +54,3 @@ import { FeedPage } from "./page"; | ||
await fs.ensureDir(dirname(dest(atomOutputFilename))); | ||
await fs.outputFile(dest(atomOutputFilename), this.feed.atom()); | ||
@@ -68,2 +70,3 @@ | ||
await fs.ensureDir(dirname(dest(jsonOutputFilename))); | ||
await fs.outputFile(dest(jsonOutputFilename), this.feed.json()); | ||
@@ -83,2 +86,3 @@ | ||
await fs.ensureDir(dirname(dest(rssOutputFilename))); | ||
await fs.outputFile(dest(rssOutputFilename), this.feed.rss()); | ||
@@ -85,0 +89,0 @@ |
@@ -67,3 +67,3 @@ import { getFeedChannelOption, getFeedLinks } from "./options"; | ||
.sort(sorter) | ||
.slice(0, feedOptions.count || 1000); | ||
.slice(0, feedOptions.count || 100); | ||
@@ -70,0 +70,0 @@ await new FeedGenerator(app, feedOptions, feedPages, { |
@@ -58,3 +58,3 @@ import type { Page } from "@vuepress/core"; | ||
* | ||
* @default 1000 | ||
* @default 100 | ||
*/ | ||
@@ -61,0 +61,0 @@ count?: number; |
Sorry, the diff of this file is not supported yet
91962
2289
+ Added@mr-hope/vuepress-shared@2.0.0-beta.6(transitive)
- Removed@mr-hope/vuepress-shared@2.0.0-beta.5(transitive)