Hello Dev Community!
Today I'll provide you with a programmatic example of how to convert dev.to articles to a Docusaurus blog. This example will use Node.js to fetch articles from the dev.to API and create Markdown files compatible with Docusaurus blog posts.
First, let's set up the project and install the necessary dependencies:
mkdir devto-to-docusaurus cd devto-to-docusaurus npm init -y npm install axios fs-extra front-matter
Now, create a file named convert.js and add the following code:
const axios = require('axios'); const fs = require('fs-extra'); const frontMatter = require('front-matter'); const path = require('path'); const DEV_TO_API_KEY = 'YOUR_DEV_TO_API_KEY'; const DEV_TO_USERNAME = 'YOUR_DEV_TO_USERNAME'; const OUTPUT_DIR = './blog'; async function fetchDevToArticles() { const response = await axios.get(`https://dev.to/api/articles/me/published`, { headers: { 'api-key': DEV_TO_API_KEY } }); return response.data; } function convertToDocusaurusFrontMatter(article) { const date = new Date(article.published_at); return { title: article.title, authors: [DEV_TO_USERNAME], tags: article.tag_list, date: date.toISOString().split('T')[0], slug: article.slug, description: article.description, }; } async function convertArticleToMarkdown(article) { const frontMatterContent = convertToDocusaurusFrontMatter(article); const markdown = `--- ${Object.entries(frontMatterContent).map(([key, value]) => `${key}: ${Array.isArray(value) ? `[${value.join(', ')}]` : value}`).join('\n')} --- ${article.body_markdown}`; const fileName = `${frontMatterContent.date}-${article.slug}.md`; const filePath = path.join(OUTPUT_DIR, fileName); await fs.outputFile(filePath, markdown); console.log(`Created: ${filePath}`); } async function main() { try { const articles = await fetchDevToArticles(); await fs.ensureDir(OUTPUT_DIR); for (const article of articles) { await convertArticleToMarkdown(article); } console.log('Conversion completed successfully!'); } catch (error) { console.error('Error:', error.message); } } main();
Here's how this script works:
- It fetches your published articles from dev.to using the API.
- For each article, it converts the metadata to Docusaurus-compatible front matter.
- It combines the front matter with the article's Markdown content.
- It saves each article as a separate Markdown file in the blog directory.
To use this script:
- Replace YOUR_DEV_TO_API_KEY with your actual dev.to API key[1].
- Replace YOUR_DEV_TO_USERNAME with your dev.to username.
- Run the script using node convert.js.
After running the script, you'll find your dev.to articles converted to Docusaurus-compatible blog posts in the blog directory[1][3].
To integrate these posts into your Docusaurus site:
- Copy the generated Markdown files from the blog directory to your Docusaurus project's blog directory.
- Ensure your docusaurus.config.js file has the blog plugin configured correctly[1][3].
Here's an example of how your docusaurus.config.js might look:
module.exports = { // ... other config options presets: [ [ '@docusaurus/preset-classic', { blog: { path: 'blog', routeBasePath: 'blog', blogTitle: 'My Dev.to Blog', blogDescription: 'A collection of my dev.to articles', blogSidebarCount: 'ALL', blogSidebarTitle: 'All Blog Posts', showReadingTime: true, editUrl: 'https://github.com/yourusername/your-repo/edit/main/website/', }, }, ], ], // ... other config options };
This configuration sets up the blog plugin to use the blog directory and display all posts in the sidebar[1][3].
Remember to customize the editUrl and other options according to your project structure and preferences. With this setup, your dev.to articles will be seamlessly integrated into your Docusaurus blog.
Citations:
[1] https://docusaurus.io/docs/blog
[2] https://dev.to/dreamlogic/how-to-use-the-multi-blog-plugin-for-docusaurus-32a2
[3] https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog
[4] https://dev.to/tuenguyen2911_67/inspired-by-docusaurus-2cm6
[5] https://dev.to/dianaiminza/documentation-using-docusaurus-40g5
[6] https://dev.to/seanyasno/starting-a-new-blogging-journey-with-docusaurus-3aap
[7] https://dev.to/lo_victoria2666/build-beautiful-documentation-websites-with-docusaurus-8o2
[8] https://dev.to/katiel/exploring-the-code-behind-docusaurus-pbk
The above is the detailed content of Dev.to post to Docusaurus blog (automation nodejs). For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
