2.13.95 • Published 8 months ago

@taktikorg/non-porro v2.13.95

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@taktikorg/non-porro

npm version npm downloads License Nuxt

This module provides extra abilities for implementation RSS feed. It's pretty similar to module-feed, but have support nuxt-content.

If you need fully customized feeds, you can freely choose any feed module (this or the mentioned above). But this module can be more flexible.

Features

  • Configured out of the box for nuxt-content
  • Supports general and specialized hooks for both feed kinds
  • Flexible: use configuration defaults (feed, item), mapping (item) or hooks for customization
  • SSR and SSG support

Configured out of the box for nuxt-content

Default settings are:

{
  feeds: {
    '/feed.atom': { revisit: '6h', type: 'atom1', content: true },
    '/feed.xml': { revisit: '6h', type: 'rss2', content: true },
    '/feed.json': { revisit: '6h', type: 'json1', content: true },
  },
  content: {
    item: {
      templateRoots: [true, 'feedme'],
    },
  },
}

General and specialized hooks

// project-name/server/plugins/feedme.ts
import type { NitroApp } from 'nitropack'

// Nitro hooks can be set only in nitro plugin
export default (nitroApp: NitroApp) => {
  // General hook: feedme:handle:content:item
  // Specialized hook: feedme:handle:content:item[*]
  //
  // When specialized hook set, general also will be called
  nitroApp.hooks.hook('feedme:handle:content:item[/contentDefaults.xml]', async ({ feed: { insert, invoke, parsed } }) => {
    if (parsed.title === 'First item') {
      // Invoke in case if item was created by another callback
      const maybeItemOptions = invoke()

      // Insert replaces current item configuration
      insert({
        ...maybeItemOptions,
        category: [
          ...maybeItemOptions?.category ?? [],
          { name: 'content hook processed' },
        ],
      })
    }
  })

  // Specialized hook for default feed
  nitroApp.hooks.hook('feedme:handle[/feed.xml]', async ({ context: { event }, feed: { create } }) => {
    // Create also replaces current feed
    create({ id: '', title: `Special feed for '${event.path}' route`, copyright: '' })
  })

  // General hook for default feed
  nitroApp.hooks.hook('feedme:handle', async ({ context: { event }, feed: { create, invoke } }) => {
    invoke() ?? create({ id: '', title: `Default feed for '${event.path}' route`, copyright: '' })
  })
}

Mapping configuration

Mapping is used for linking feed item object key to the path in parsed content:

{
  item: {
    mapping: [
      // Third item is optional mapping function
      ['date', 'modified', value => value ? new Date(value) : value],
      // When mapping function result is undefined - next variant applied
      ['date', 'created', value => value ? new Date(value) : value],
      // Until the real one value will be set
      ['date', '', () => new Date()],
      // By default mapping is x => x
      ['link', '_path'],
    ],
    // Create default mappings with indicated roots:
    //   [keyof Item /* such as image, id, link */, root + keyof Item]
    //
    // The true value means use empty root:
    //   ['link', 'link']
    //
    // Where any other key means use this as path to value:
    //  ['link', `{root}.link`]
    //
    // Root can be separate by `.` which allows to deep invoking
    templateRoots: [true, 'feedme'],
  }
}

NOTE: Date value is a special case for feed module, so by default mapping provides the next map for the date field: value => value ? new Date(value) : new Date() So in case when you provide your own alias for date - you need to provide map function

NOTE: The mapping function is serialized so its required to not to have any references in outer scopes

Tags

Tags allow to replace node values according to match:

{
  // Allows to pass optional map function
  tags: [
    // This tags replace first empty symbol if value starts with /
    // Example: /link -> urlBase/link
    [/^(?=\/)/, urlBase],
  ],
}

Note: Tags applied recursively, item.field.inner (value) is affected

Quick Setup

  1. Add @taktikorg/non-porro dependency to your project

Use your favorite package manager (I prefer yarn)

yarn add -D @taktikorg/non-porro

pnpm add -D @taktikorg/non-porro

npm install --save-dev @taktikorg/non-porro
  1. Add @taktikorg/non-porro to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    // After nuxt content
    '@nuxt/content',
    '@taktikorg/non-porro'
  ]
})

That's it! You can now use @taktikorg/non-porro in your Nuxt app ✨

keysuuidvpces5globbinariespostcssstreamFloat32Array-0monorepoelasticachequeueeslinttypesafecurlzeroeffect-tsFunction.prototype.nameRegExp#flagspathpromisespinnersreadebselectronStyleSheetharmonyjasminearraybufferworkspace:*assertscloudsearchfigletsyntaxerrorUint32ArraystructuredCloneWebSocketsremovetoArraybabelArrayBufferimportexporteventsargsconstrequirees-shimscjkhttpdragxmlworkflowforkjsdomObject.isreduxcharacternpmec2real-timelocationownmake dirvalidatorcomputed-typesprotoconcatMapes2017atomdefinePropertygetPrototypeOfkeybeanstalkhttpsexecuteisConcatSpreadablesetterWebSocketinstrumentationreact-hooksregular expressiontesterramdatypedfind-upSymbolparseAsyncIteratorroutearktypesimpledbnodejsflatMapWeakSetschemeprefixrm -frflatReactiveExtensionschildidentifiersfetchfindupmochanodequerystringdayjs.envTypedArraydirfromfunction.lengtha11ytsgetOwnPropertyDescriptordeepcopytostringtagtapedescriptorsagenttoolsframersettingsbusysameValueZerosortReflect.getPrototypeOffast-copyregexinputspawnperformancedeterministic6to5getwalkingcommandmatchesoptionxhrchannelmatchAllfolderglobalThisforEachelbObject.valuesassertionpushsliceapiupnameswindowString.prototype.matchAlldynamodbcoerciblefile systemArray.prototype.findLastCSSStyleDeclarationdataViewStreamsBigInt64Arrayvalidatecallbindurlintrinsichooksprivate dataamazonargvtacitcodesES2019ECMAScript 2018utilitynopeimmutableTypeScriptnegativejsonschemapropertiescoveragenativeassigncore-jstrimLeftgroupByglacierindicatorstabletextObservablewhichURLendershrinkwrapSymbol.toStringTagUint8ClampedArrayreversedArray.prototype.includesArrayrfc4122byteWeakMapjestclienttrimEndshellregular-expressionArray.prototype.filter[[Prototype]]animationECMAScript 6hasdeepcloneIteratordatemanagerhasOwnPropertycontainsargument0spinnervalidutilitieses-shim APIweakmapwgetxtermarraylooksetPrototypeOfreversetimeenvironmentserializationcallpicomatchwafparenttelephoneexpressionruntimebyteOffsetsymlinksswfrmESnextspecglobalsclass-validatoristakeregularschematypanionES2023touchMicrosoftbrowserfindpackageprocessselfjapanesepackagestc39fast-deep-copyeslintpluginmodulesstringifybinduser-streamsES2016fullwidthaccessibilitytraverseonceECMAScript 2023@@toStringTagflagmatchStreamgraphqlqueueMicrotasklibphonenumbertyped arraytoReversedtoobjectflattenspringfindLastJSON-Schemareact animationiamMapnpmignoredirectoryES3parserdataviewInt32Arrayzxidlepipesns3dregular expressionsglobaltestingsearchsomelanguagebundlingutil.inspectserializercopycolumntypeofArray.prototype.flattencheckreact-testing-librarycachespeedReactiveXphonereact-hook-formthreedescriptorqslengthwritablehashlinklrupropertybrowserlistpruneio-tsArray.prototype.flatartbinenvironmentsreadableRxJSvaluesautoprefixergenericsslotes2015fnmatchtrimRightroutingmoveInt8Arrayvariableslook-upES2018ES8fpscompilertransportistanbulObservablescollection.es6rdsInt16ArrayextratrimfastcloneArray.prototype.flatMaprecursivees-abstracttypeomitinternalredactfunctionloggingBigUint64ArrayfsES2021objESincludesenvreworkrouter.gitignorePushchaiecmascriptglobal objectyuptrimStartwhatwgcharactersfunctional__proto__Float64ArrayES5efficientmrusetImmediatetypedarraysequalityminimalsuperstructwaitpackage.jsonObject.fromEntriespolyfillcall-bindArray.prototype.containscssreusecolorsemrCSSbinaryObject.definePropertyECMAScript 2016arraysredirectposeextendhtmlmkdirkoreancloudtrailstoragegatewayfileidwritenegative zeroes7zodHyBicircularpopmotionvalidationsharedarraybuffercloudfrontregexpfeedquotecloudformationajaxassertgdprbannerignoreSetdefinewebECMAScript 2019awesomesauceArray.prototype.findLastIndexmapreducelocalrgbformjsObject.keysrandomansicolumnscss-in-jsnamefunctionsclirangeerrorendpointjson-schema-validationes2016optimizerformses2018route53Object.entriesjshintaccessorprotobufconfigmobilepyyamlobjectescapeJSONdom-testing-libraryrulesexpresscolorexecsqsform-validationgetterfulljoistylingcallboundString.prototype.trimjsonapollormdireveryloggerlastcolourtypedarrayhasOwnstyleentriesreadablestreampoint-freewarningparentssinatraoptimisthardlinkstypesfilterES7_.extendrobustjavascriptECMAScript 5fpexecfileesgetintrinsicURLSearchParamschromeuninstallresti18ndebugasciilockfilecensorshebangconsumefastifyairbnboffsetappreduceracorncallbackmakedeepmulti-packagestringloadingmaphas-ownyamlfast-clonepluginlistenerswaapifastpnpm9diffES2017findLastIndexformatreactshamUint16ArrayES2022karmaiterateastsymbolcommandervarsECMAScriptworkertddRFC-6455walkdependency managervesttslibchineseprivateweaksethelperes8groupemojigetopteslintconfigmkdirstestdebuggerstyleguideflagsasynccomparejsdiffoutputimmerdomfantasy-landframeworkpostcss-pluginterminalRxes6seteventDispatcherECMAScript 2021sharedtypescriptbdd$.extend
2.13.95

8 months ago

2.13.94

8 months ago

2.13.93

8 months ago

2.13.92

8 months ago

2.13.91

8 months ago

2.13.90

8 months ago

2.13.89

8 months ago

2.13.88

8 months ago

2.13.87

8 months ago

2.13.86

8 months ago

2.13.85

8 months ago

2.12.85

8 months ago

2.12.84

8 months ago

2.12.83

8 months ago

2.12.82

8 months ago

2.12.81

8 months ago

2.12.80

8 months ago

2.12.79

8 months ago

2.12.78

8 months ago

2.12.77

8 months ago

2.12.76

8 months ago

2.12.75

8 months ago

2.12.74

8 months ago

2.12.73

8 months ago

2.12.72

8 months ago

2.12.71

8 months ago

2.12.70

9 months ago

2.12.69

9 months ago

2.12.68

9 months ago

2.12.67

9 months ago

2.11.67

9 months ago

2.11.66

9 months ago

2.11.65

9 months ago

2.11.64

9 months ago

2.11.63

9 months ago

2.10.63

9 months ago

2.10.62

9 months ago

2.10.61

9 months ago

2.10.60

9 months ago

2.10.59

9 months ago

2.10.58

9 months ago

2.10.57

9 months ago

2.10.56

9 months ago

2.10.55

9 months ago

2.10.54

9 months ago

2.10.53

9 months ago

2.10.52

9 months ago

2.10.51

9 months ago

2.10.50

9 months ago

2.10.49

9 months ago

2.10.48

9 months ago

2.10.47

9 months ago

2.9.47

9 months ago

2.9.46

9 months ago

2.9.45

9 months ago

2.8.45

9 months ago

2.8.44

10 months ago

2.8.43

10 months ago

2.8.42

10 months ago

2.7.42

10 months ago

2.7.41

10 months ago

1.7.41

10 months ago

1.7.40

10 months ago

1.6.40

10 months ago

1.6.39

10 months ago

1.6.38

10 months ago

1.6.37

10 months ago

1.6.36

10 months ago

1.6.35

10 months ago

1.6.34

10 months ago

1.6.33

10 months ago

1.6.32

10 months ago

1.6.31

10 months ago

1.5.31

10 months ago

1.5.30

10 months ago

1.5.29

10 months ago

1.5.28

10 months ago

1.5.27

10 months ago

1.5.26

10 months ago

1.5.25

10 months ago

1.4.25

10 months ago

1.4.24

10 months ago

1.3.24

10 months ago

1.3.23

10 months ago

1.3.22

10 months ago

1.3.21

10 months ago

1.3.20

11 months ago

1.3.19

11 months ago

1.3.18

11 months ago

1.3.17

11 months ago

1.3.16

11 months ago

1.2.16

11 months ago

1.2.15

11 months ago

1.2.14

11 months ago

1.2.13

11 months ago

1.2.12

11 months ago

1.1.12

11 months ago

1.1.11

11 months ago

1.1.10

11 months ago

1.1.9

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago