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

exporter: wordpress export action #639

Draft
wants to merge 3 commits into
base: main
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"flatfilers/*",
"plugins/*",
"support/*",
"utils/*"
"utils/*",
"validators/*"
],
"scripts": {
"clean": "find ./ '(' -name 'node_modules' -o -name 'dist' -o -name '.turbo' -o -name '.parcel-cache' ')' -type d -exec rm -rf {} +",
Expand Down
71 changes: 71 additions & 0 deletions validators/WordpressCMSExporter/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Flatfile WordPress CMS Export Plugin

This Flatfile Listener plugin enables seamless export of data to WordPress CMS. It provides a robust solution for mapping fields, handling custom fields, applying default settings, previewing posts, and batch exporting to WordPress.

## Features

- Field mapping from Flatfile to WordPress post structure
- Custom field handling
- Default settings application
- Post preview generation
- Batch export to WordPress
- WordPress API authentication
- Error handling and reporting

## Installation

To install the plugin, use npm:

```bash
npm install @flatfile/plugin-wordpress-export
```

## Example Usage

```javascript
import { FlatfileListener } from "@flatfile/listener";
import WordpressCMSExport from "@flatfile/plugin-wordpress-export";

const listener = new FlatfileListener();
const wordpressExport = WordpressCMSExport(listener);

// Your additional listener configurations...

export default listener;
```

## Configuration

The plugin requires WordPress API credentials to be configured. You can set these in your Flatfile space metadata:

```javascript
await api.spaces.update(workspaceId, {
metadata: {
wpConfig: {
apiUrl: "https://your-wordpress-site.com",
username: "your-username",
password: "your-password",
},
},
});
```

## Behavior

1. **Field Mapping**: The plugin maps Flatfile fields to WordPress post fields, including title, content, status, date, author, categories, and tags.

2. **Custom Fields**: Any field prefixed with "custom_" in Flatfile will be treated as a custom field in WordPress.

3. **Default Settings**: Default settings for post status, author, categories, and tags are applied if not provided in the Flatfile record.

4. **Post Preview**: A HTML preview of each post is generated before export.

5. **Batch Export**: Posts are exported in batches to the configured WordPress site using the WordPress REST API.

6. **Error Handling**: Any errors during the export process are logged and reported back to Flatfile.

7. **Job Progress**: The plugin updates the job progress in Flatfile, providing real-time feedback on the export process.

8. **Workspace Metadata**: After a successful commit, the plugin updates the workspace metadata to indicate that WordPress configuration is required.

This plugin streamlines the process of exporting data from Flatfile to WordPress, handling the complexities of field mapping, custom fields, and API interactions.
91 changes: 91 additions & 0 deletions validators/WordpressCMSExporter/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"timestamp": "2024-09-25T16-44-49-645Z",
"task": "Create a Wordpress CMS Export Flatfile Listener plugin:\n - Implement a custom action to export data to Wordpress\n - Allow users to select the target CMS platform and provide necessary API credentials\n - Map Flatfile fields to corresponding CMS fields (e.g., title, content, author, categories, tags)\n - Support exporting rich text content, including formatting and embedded media\n - Implement options for post status (draft, published) and scheduling\n - Handle batch processing for efficient export of multiple posts\n - Provide error handling and reporting for failed exports\n - Allow configuration of default post settings (e.g., featured image, excerpt)\n - Implement a preview function to review post formatting before export\n - Support updating existing posts by matching on a unique identifier\n - Include options for handling custom fields specific to each CMS platform",
"summary": "This code implements a Flatfile Listener plugin for exporting data to WordPress CMS. It includes functionality for mapping fields, handling custom fields, applying default settings, previewing posts, and batch exporting to WordPress. The plugin allows users to configure WordPress API credentials and select export options.",
"steps": [
[
"First, let's retrieve information about Flatfile Listeners and the Record Hook plugin to understand the basic structure we'll be working with.\n",
"#E1",
"PineconeAssistant",
"Provide information on Flatfile Listeners and the Record Hook plugin, including their basic structure and usage",
"Plan: First, let's retrieve information about Flatfile Listeners and the Record Hook plugin to understand the basic structure we'll be working with.\n#E1 = PineconeAssistant[Provide information on Flatfile Listeners and the Record Hook plugin, including their basic structure and usage]"
],
[
"Implement the custom action to export data to Wordpress. We'll need to use the Wordpress REST API for this.\n",
"#E3",
"Google",
"Wordpress REST API documentation for creating posts",
"Plan: Implement the custom action to export data to Wordpress. We'll need to use the Wordpress REST API for this.\n#E3 = Google[Wordpress REST API documentation for creating posts]"
],
[
"Implement field mapping functionality to map Flatfile fields to corresponding CMS fields.\n",
"#E5",
"LLM",
"Create a function called mapFields that takes in Flatfile record data and returns an object with mapped Wordpress fields (title, content, author, categories, tags). Include support for rich text content",
"Plan: Implement field mapping functionality to map Flatfile fields to corresponding CMS fields.\n#E5 = LLM[Create a function called mapFields that takes in Flatfile record data and returns an object with mapped Wordpress fields (title, content, author, categories, tags). Include support for rich text content]"
],
[
"Add support for post status and scheduling options.\n",
"#E6",
"LLM",
"Extend the exportToWordpress function from #E4 to include options for post status (draft, published) and scheduling. Add these options to the function parameters",
"Plan: Add support for post status and scheduling options.\n#E6 = LLM[Extend the exportToWordpress function from #E4 to include options for post status (draft, published) and scheduling. Add these options to the function parameters]"
],
[
"Implement batch processing for efficient export of multiple posts.\n",
"#E7",
"LLM",
"Create a function called batchExport that takes an array of records and processes them in batches using the exportToWordpress function from #E6. Include error handling and reporting for failed exports",
"Plan: Implement batch processing for efficient export of multiple posts.\n#E7 = LLM[Create a function called batchExport that takes an array of records and processes them in batches using the exportToWordpress function from #E6. Include error handling and reporting for failed exports]"
],
[
"Add configuration options for default post settings.\n",
"#E8",
"LLM",
"Create a function called applyDefaultSettings that takes in post data and default settings (e.g., featured image, excerpt) and applies them to the post data before export",
"Plan: Add configuration options for default post settings.\n#E8 = LLM[Create a function called applyDefaultSettings that takes in post data and default settings (e.g., featured image, excerpt) and applies them to the post data before export]"
],
[
"Implement a preview function to review post formatting before export.\n",
"#E9",
"LLM",
"Create a function called previewPost that takes in mapped post data and returns a formatted preview of the post, including HTML rendering of rich text content",
"Plan: Implement a preview function to review post formatting before export.\n#E9 = LLM[Create a function called previewPost that takes in mapped post data and returns a formatted preview of the post, including HTML rendering of rich text content]"
],
[
"Add support for updating existing posts by matching on a unique identifier.\n",
"#E10",
"LLM",
"Extend the exportToWordpress function from #E6 to check for existing posts using a unique identifier (e.g., slug or custom field) and update the post if it exists, otherwise create a new post",
"Plan: Add support for updating existing posts by matching on a unique identifier.\n#E10 = LLM[Extend the exportToWordpress function from #E6 to check for existing posts using a unique identifier (e.g., slug or custom field) and update the post if it exists, otherwise create a new post]"
],
[
"Implement options for handling custom fields specific to Wordpress.\n",
"#E11",
"LLM",
"Create a function called handleCustomFields that takes in custom field data and adds it to the post data before export. Include support for common Wordpress custom field plugins",
"Plan: Implement options for handling custom fields specific to Wordpress.\n#E11 = LLM[Create a function called handleCustomFields that takes in custom field data and adds it to the post data before export. Include support for common Wordpress custom field plugins]"
],
[
"Combine all the created functions into the main listener logic.\n",
"#E12",
"LLM",
"Combine the functions created in #E2, #E4, #E5, #E6, #E7, #E8, #E9, #E10, and #E11 into a complete Flatfile Listener plugin. Include logic to allow users to select export options and provide API credentials. Ensure that the listener subscribes only to valid Event Topics",
"Plan: Combine all the created functions into the main listener logic.\n#E12 = LLM[Combine the functions created in #E2, #E4, #E5, #E6, #E7, #E8, #E9, #E10, and #E11 into a complete Flatfile Listener plugin. Include logic to allow users to select export options and provide API credentials. Ensure that the listener subscribes only to valid Event Topics]"
],
[
"Perform a final check on the complete plugin code, removing any unused imports and validating that all parameters are correct for the plugins used.\n",
"#E13",
"LLM",
"Review the complete plugin code from #E12, remove any unused imports, and validate that all parameters are correct for the plugins used. Ensure that the listener only subscribes to valid Event Topics. Provide the final, cleaned-up version of the WordpressCMSExport plugin code",
"Plan: Perform a final check on the complete plugin code, removing any unused imports and validating that all parameters are correct for the plugins used.\n#E13 = LLM[Review the complete plugin code from #E12, remove any unused imports, and validate that all parameters are correct for the plugins used. Ensure that the listener only subscribes to valid Event Topics. Provide the final, cleaned-up version of the WordpressCMSExport plugin code]"
]
],
"metrics": {
"tokens": {
"plan": 4324,
"state": 6167,
"total": 10491
}
}
}
68 changes: 68 additions & 0 deletions validators/WordpressCMSExporter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "@flatfile/plugin-wordpress-cms-export",
"version": "1.0.0",
"description": "A Flatfile plugin for exporting data to WordPress CMS",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"browser": {
"./dist/index.js": "./dist/index.browser.js",
"./dist/index.mjs": "./dist/index.browser.mjs"
},
"exports": {
"types": "./dist/index.d.ts",
"node": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"browser": {
"require": "./dist/index.browser.js",
"import": "./dist/index.browser.mjs"
},
"default": "./dist/index.mjs"
},
"source": "./src/index.ts",
"files": [
"dist/**"
],
"scripts": {
"build": "rollup -c",
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
},
"keywords": [
"flatfile",
"plugin",
"wordpress",
"cms",
"export",
"flatfile-plugins",
"category-transform"
],
"author": "Your Name",
"license": "MIT",
"dependencies": {
"@flatfile/listener": "^1.0.5",
"@flatfile/api": "^1.9.15",
"@flatfile/plugin-record-hook": "^1.7.0",
"axios": "^1.7.7",
"node-html-parser": "^6.1.13"
},
"devDependencies": {
"@flatfile/hooks": "^1.5.0",
"@flatfile/rollup-config": "^0.1.1",
"typescript": "^5.6.2",
"@types/node": "^22.7.0"
},
"repository": {
"type": "git",
"url": "https://github.com/YourGitHubUsername/flatfile-plugin-wordpress-cms-export.git"
},
"browserslist": [
"> 0.5%",
"last 2 versions",
"not dead"
]
}
38 changes: 38 additions & 0 deletions validators/WordpressCMSExporter/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { buildConfig } from '@flatfile/rollup-config';
import typescript from '@rollup/plugin-typescript';

const umdExternals = [
'@flatfile/api',
'@flatfile/listener',
'@flatfile/plugin-record-hook',
'axios',
'node-html-parser'
];

const config = buildConfig({
input: 'src/index.ts', // Assuming your main file is src/index.ts
includeUmd: true,
umdConfig: {
name: 'WordpressCMSExport',
external: umdExternals
},
plugins: [
typescript({
tsconfig: './tsconfig.json',
declaration: true,
declarationDir: 'dist/types',
})
]
});

// Ensure all builds use the TypeScript plugin
config.forEach(conf => {
if (!conf.plugins.find(plugin => plugin.name === 'typescript')) {
conf.plugins.push(typescript({
tsconfig: './tsconfig.json',
declaration: false,
}));
}
});

export default config;
Loading
Loading