Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nuxt 3 support #114

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion .editorconfig
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# editorconfig.org
root = true

[*]
Expand Down
8 changes: 1 addition & 7 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
# Common
node_modules
dist
.nuxt
coverage

# Plugin
lib/plugin.js
node_modules
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@nuxt/eslint-config"]
}
6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/ci.yml

This file was deleted.

57 changes: 52 additions & 5 deletions .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
# Dependencies
node_modules
*.iml
.idea

# Logs
*.log*

# Temp directories
.temp
.tmp
.cache

# Yarn
**/.yarn/cache
**/.yarn/*state*

# Generated dirs
dist

# Nuxt
.nuxt
.vscode
.DS_Store
.output
.vercel_build_output
.build-*
.env
.netlify

# Env
.env

# Testing
reports
coverage
dist
*.lcov
.nyc_output

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Intellij idea
*.iml
.idea

# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
2 changes: 2 additions & 0 deletions .nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports.autoImport=false
typescript.includeWorkspace=true
211 changes: 44 additions & 167 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,202 +1,79 @@
# Feed module - Everyone deserves RSS, Atom and Json
# Nuxt Feed Module

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
[![Codecov][codecov-src]][codecov-href]
[![License][license-src]][license-href]
[![Nuxt][nuxt-src]][nuxt-href]

> Feed module enables everyone to have RSS, Atom and Json.
Feed module enables everyone to have RSS, Atom and Json.

[📖 **Release Notes**](./CHANGELOG.md)
- [✨  Release Notes](/CHANGELOG.md)

## Features

- Three different feed types (RSS 2.0, ATOM 1.0 and JSON 1.0)
- As many feeds as you like!
- Completely customizable. Need to fetch data before? No problem!
- Works with **all modes** (yes, even generate!)
- For Nuxt 2.x and higher
- 🪄  Three different feed types (ATOM 1.0, JSON 1.0, and RSS 2.0)
- 👌  As many feeds as you like
- 📦  Completely customizable
- 🚀  [Nuxt 3](https://nuxt.com) support

## Setup
## Quick Setup

1. Add `@nuxtjs/feed` dependency to your project

```bash
yarn add @nuxtjs/feed # or npm install @nuxtjs/feed
# Using pnpm
pnpm add -D @nuxtjs/feed
# Using yarn
yarn add --dev @nuxtjs/feed
# Using npm
npm install --save-dev @nuxtjs/feed
```

2. Add `@nuxtjs/feed` to the `modules` section of `nuxt.config.js`
2. Add `@nuxtjs/feed` to the `modules` section of `nuxt.config.ts`

```js
export default {
modules: [
['@nuxtjs/feed', {
// Your feeds here
}]
]
}
```

### Using top level options

```js
export default {
export default defineNuxtConfig({
modules: [
'@nuxtjs/feed'
],
feed: [
// Your feeds here
]
}
```

## Configuration

So... how to get these feeds working now?

### Configuration object overview

```js
export default {
feed: [
// A default feed configuration object
{
path: '/feed.xml', // The route to your feed.
async create(feed) {}, // The create function (see below)
cacheTime: 1000 * 60 * 15, // How long should the feed be cached
type: 'rss2', // Can be: rss2, atom1, json1
data: ['Some additional data'] // Will be passed as 2nd argument to `create` function
}
]
}
```

### Feed create function

Let's take a closer look on the `create` function. This is the API that
actually modifies your upcoming feed.

A simple create function could look like this:

```js
import axios from 'axios'

// In your `feed` array's object:
async create (feed) {
feed.options = {
title: 'My blog',
link: 'https://lichter.io/feed.xml',
description: 'This is my personal feed!'
}

const posts = await (axios.get('https://blog-api.lichter.io/posts')).data
posts.forEach(post => {
feed.addItem({
title: post.title,
id: post.url,
link: post.url,
description: post.description,
content: post.content
})
})

feed.addCategory('Nuxt.js')

feed.addContributor({
name: 'Alexander Lichter',
email: '[email protected]',
link: 'https://lichter.io/'
})
}
})
```

Feed creation is based on the [feed](https://github.com/jpmonette/feed) package.
Please use it as reference and further documentation for modifying the `feed` object
that is passed to the `create` function.

Using the `create` function gives you almost unlimited possibilities to customize your feed!

### Using a feed factory function

There is one more thing. Imagine you want to add a feed per blog category, but you don't want
to add every category by hand.

You can use a `factory function` to solve that problem. Instead of a hardcoded array, you can setup
a function that will be called up on feed generation. The function **must** return an array with all
feeds you want to generate.
That's it! You can now use Nuxt Feed Module in your Nuxt app ✨

```js
export default {
feed: async () => {
const posts = (await axios.get('https://blog-api.lichter.io/posts')).data
const tags = (await axios.get('https://blog-api.lichter.io/tags')).data

return tags.map(t => {
const relevantPosts = posts.filter(/*filter posts somehow*/)

return {
path: `/${t.slug}.xml`, // The route to your feed.
async create(feed) {
feed.options = {
title: `${t.name} - My blog`,
link: `https://blog.lichter.io/${t.slug}.xml`,
description: `All posts related to ${t.name} of my blog`
}

relevantPosts.forEach(post => {
feed.addItem({
title: post.title,
id: post.id,
link: `https://blog.lichter.io/posts/${post.slug}`,
description: post.excerpt,
content: post.text
})
})
},
cacheTime: 1000 * 60 * 15,
type: 'rss2'
}
})
}
}
```
## Configuration

In case you want to pass in data into the factory function, you can use a *factory object*.

```js
export default {
feed: {
data: ['Your data here'],
factory: (dataFromFeedDotData) => {/* your factory function */}
}
}
```
TBD

## Development

1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `npm run dev`

## License

[MIT License](./LICENSE)

Copyright (c) - Nuxt Community
```bash
# Install dependencies
pnpm install
# Generate type stubs
pnpm run dev:prepare
# Develop with the playground
pnpm run dev
# Build the playground
pnpm run dev:build
# Run ESLint
pnpm run lint
# Run Vitest
pnpm run test
pnpm run test:watch
# Release new version
pnpm run release
```

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/feed/latest.svg
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/feed/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/@nuxtjs/feed

[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/feed.svg
[npm-downloads-src]: https://img.shields.io/npm/dm/@nuxtjs/feed.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/feed

[github-actions-ci-src]: https://github.com/nuxt-community/feed-module/workflows/ci/badge.svg
[github-actions-ci-href]: https://github.com/nuxt-community/feed-module/actions?query=workflow%3Aci

[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/feed-module.svg
[codecov-href]: https://codecov.io/gh/nuxt-community/feed-module

[license-src]: https://img.shields.io/npm/l/@nuxtjs/feed.svg
[license-src]: https://img.shields.io/npm/l/@nuxtjs/feed.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/@nuxtjs/feed

[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
[nuxt-href]: https://nuxt.com/modules/module-feed
5 changes: 0 additions & 5 deletions commitlint.config.js

This file was deleted.

Loading