项目作者: Junscuzzy

项目描述 :
CLI tool that fetch WordPress data to produce ndjson files for sanity.io importation
高级语言: TypeScript
项目地址: git://github.com/Junscuzzy/wordpress-to-ndjson.git
创建时间: 2020-04-29T22:08:02Z
项目社区:https://github.com/Junscuzzy/wordpress-to-ndjson

开源协议:

下载


WordPress to NDJSON formatter

Simple NodeJS CLI-Application that fetch and format data from WordPress, and create NDJSON output to import it in Sanity.io CMS.

Getting started

Download and install the repository locally

  1. git clone wordpress-to-ndjson https://github.com/Junscuzzy/wordpress-to-ndjson
  2. cd wordpress-to-ndjson
  3. npm install

Then run

  1. npm run dev --url https://your-wordpress-site.com

Output format

This script makes a *.ndjson files for the following schema:

  1. // studio/schemas/documents/post.js
  2. export default {
  3. name: 'post',
  4. type: 'document',
  5. title: 'Blog posts',
  6. fields: [
  7. {
  8. name: 'title',
  9. type: 'string',
  10. title: 'Title',
  11. },
  12. {
  13. name: 'slug',
  14. type: 'slug',
  15. title: 'Slug',
  16. options: {
  17. source: 'title',
  18. maxLength: 96
  19. }
  20. },
  21. {
  22. name: 'mainImage',
  23. type: 'mainImage',
  24. title: 'Main image'
  25. },
  26. {
  27. name: 'excerpt',
  28. type: 'text',
  29. rows: 4,
  30. title: 'Excerpt',
  31. },
  32. {
  33. name: 'categories',
  34. type: 'array',
  35. title: 'Categories',
  36. of: [
  37. {
  38. type: 'reference',
  39. to: {
  40. type: 'category'
  41. }
  42. }
  43. ]
  44. },
  45. {
  46. name: 'body',
  47. type: 'bodyPortableText',
  48. title: 'Body text'
  49. }
  50. ]
  51. }
  52. // studio/schemas/documents/category.js
  53. export default {
  54. name: 'category',
  55. type: 'document',
  56. title: 'Categories',
  57. fields: [
  58. {
  59. name: 'title',
  60. type: 'string',
  61. title: 'Title'
  62. },
  63. {
  64. name: 'slug',
  65. type: 'slug',
  66. title: 'Slug',
  67. options: {
  68. source: 'title',
  69. maxLength: 96
  70. }
  71. },
  72. {
  73. name: 'description',
  74. type: 'text',
  75. title: 'Description'
  76. }
  77. ]
  78. }

Evolution

Actually, your can only fetch posts and post categories. If you want edit the formatting schema or add entities:

  1. Update the Typescript interface model in src/interfaces/{post-type}.ts
  2. Update the formatter following typescript support in src/models/{post-type}.ts
  3. If necessary, edit the index file named src/bin/cli.ts.

You can copy this repository and adapt this following your business logic or submit a PR ;).

To-do

  • CPT support
  • ACF support
  • Custom sanity.io output format
  • Use wp-api instead REST API
  • Authenticated connection to wordPress
  • Add unit tests

License

Un-licensed, you can use, copy, edit, share (…) as you want without credit or permission.