You can clone/copy and modify this repo to your liking.
Your markdown-exported Wordpress blog posts should be placed in: src/posts/
Please see this blog for details:
👉 How to Convert a Wordpress blog to Astro Static Site Generator
- Follow the instructions in the companion blog post to export your Wordpress posts and content.
- Clone or copy this project.
- Place your markdown-ified Wordpress posts in
src/posts(subfolders work too). - Place your mirrored
wp-contentfolder inpublic/. The most important subfolder of this iswp-content/uploads, which contains your pictures. You might or might not need the rest. - Install project dependencies by running
npm install. You need Node.js22.19.0or newer (Astro 7 and its dependencies require it). - Disable Astro telemetry:
./node_modules/.bin/astro telemetry disable(this only needs to be done once) - Run
npm run buildto generate site indist/and check for errors - Run
npm run devto serve the site locally and monitor files for changes. You can make any modifications as needed to the files undersrc/so that your blog looks and behaves the way you'd like it - Don't forget to update files
astro.config.mjsandconfig.tswith values that are relevant to your website!
When you run npm run build, your website will be saved to the dist/ folder. How you'd like to deploy it then is up to you. There are many options.
Finally, there are some things to keep in mind:
- The following frontmatter is required:
title,date,author,permalink,categories,tags - The following frontmatter is optional:
layout,draft,id - You can set
draft: trueto prevent a post from appearing on the generated website - Make sure that the URL in
permalinkbegins and ends with a/ - You should generate the
datevalue indatelike so:node -e "console.log(new Date().toISOString())" layoutis a path relative to the post file, and it must point to a file insrc/layouts/. For a post insrc/posts/, it is'../layouts/BlogPost.astro'. For a post insrc/posts/sub/, it is'../../layouts/BlogPost.astro'. A post withoutlayoutusessrc/layouts/BlogPost.astro..mdxposts work too, with these differences:- Do not set
layoutin an.mdxpost. The build stops with an error..mdxposts always usesrc/layouts/BlogPost.astro. - Write the "more" marker as
<Fragment set:html="<!--more-->" />. A plain<!--more-->is a syntax error in MDX. - The list pages and the RSS feed get the HTML of
.mdxposts from Astro's experimental Container API. A future Astro upgrade can break this..mdposts use it only if they have a Markdown image with a relative path (see the point about images below). - The post previews on the list pages and in the RSS feed do not have the CSS of the components that you use in an
.mdxpost. The post page has it.
- Do not set
- Astro processes Markdown images with a relative path, for example
. It optimizes them (a.pngbecomes a.webp, for example) and puts them indist/_astro/. For an.mdpost with such an image, the list pages and the RSS feed get the HTML from the Container API too. Image paths that start with/(for example/wp-content/uploads/...) stay as they are. - A paragraph that contains only the URL of an oEmbed provider (for example YouTube or Twitter) becomes an embed. The build downloads the embed data, so it needs internet access. Astro caches
.mdposts, so a build downloads embeds only for new or changed.mdposts (a change toastro.config.mjsclears this cache)..mdxposts download their embeds on every build. If an embed fails, the build stops, except for Twitter links: these show a red error message instead. - Many of the newly added files do not fit in with the markup and styling of the original template, and probably won't fit in with the styling and markup of your Wordpress site either. You will need to modify them to look good.
- When making changes to the template, if things suddenly don't work, try running
npm run buildinstead ofnpm run dev, as that seems more likely to identify and catch bugs.
This project is a fork of version 1.1.0 of the create-astro project. It has since been upgraded to Astro 7.
The following differences exist:
- Wordpress-specific modifications:
- Posts:
src/content.config.js: all.mdand.mdxfiles insrc/posts/and its subfolders make up thepostscontent collectionsrc/js/util.js:getPosts()returns the posts without drafts, newest first.postHTML()returns the HTML of a post (.mdor.mdx). All pages and the RSS feed get their posts from these two functions.
- URL preservation:
src/pages/[...wp].astro: preserves original wordpress permalinks for posts, as defined by the frontmatterpermalink. It also applies thelayoutof the post.src/pages/author/[slug].astro: wordpress-URL for listing posts for specific authorsrc/pages/category/[slug].astro: wordpress-URL for listing posts for specific categorysrc/pages/tag/[slug].astro: wordpress-URL for listing posts for specific tagsrc/pages/page/[page].astro: wordpress-URL pagination support for listing all of your posts (/page/1/,/page/2/, and so on). The homepage (src/pages/index.astro) still shows the welcome text of the template.- The orignal template's
src/pages/blog/folder has been removed. Posts now go insrc/posts/
- Components:
src/components/WPArticleSummary.astro: shows a post in a list of posts. On/page/N/, it shows the text before the<!--more-->marker if the post has one. Otherwise, and on the author, category, and tag pages, it shows the first words of the post.src/components/PostFooter.astro: optional footer under posts to link to related categories, tags, etc.src/components/Sidebar.astro: sidebar widgets to list categories and recent posts (not used by default)src/components/Search.astro: non-functioning search widget. Feel free to implement it and send a PR!
- Posts:
- Added the following dependencies:
@astrojs/markdown-remark: itsunified()Markdown processor (set inastro.config.mjs) runs the remark plugins below. Astro 7's default Markdown processor ignores remark plugins and shows no error.remark-breaks: better newline handling in markdown filesremark-gfm: support for rendering tables in markdown files@remark-embedder/core&@remark-embedder/transformer-oembed: support for rendering Twitter and YouTube links as embeds
src/pages/rss.xml.js: an RSS feed with the first 100 words or so of each post and a "Read more" link. Drafts are not in the feed.astro.config.mjssetscompressHTML: true. It keeps the whitespace between HTML elements. Astro 7's default removes it, and then for example the links in the post footer run together.- Added support for
@in imports to make it easy to import files without using../../../etc. - Added
PAGE_SIZEconfig variable tosrc/config.ts .npmrcnow usessave-exact = trueandmin-release-age=14, so npm only installs package versions that are at least 14 days old
(What follows is the original unmodified README from the official Astro blog template.)
# okTurtles Note: DO NOT DO THIS!
# Clone this repo, or download a zipped version of it instead.
# Running the command below will install the unmodified version
# of the Astro blog template, which doesn't have Wordpress support.
npm create astro@latest -- --template blog
🧑🚀 Seasoned astronaut? Delete this file. Have fun!
Features:
- ✅ Minimal styling (make it your own!)
- ✅ 100/100 Lighthouse performance
- ✅ SEO-friendly with canonical URLs and OpenGraph data
- ✅ Sitemap support
- ✅ RSS Feed support
- ✅ Markdown & MDX support
Inside of your Astro project, you'll see the following folders and files:
├── public/
├── src/
│ ├── components/
│ ├── layouts/
│ └── pages/
├── astro.config.mjs
├── README.md
├── package.json
└── tsconfig.json
Astro looks for .astro or .md files in the src/pages/ directory. Each page is exposed as a route based on its file name.
There's nothing special about src/components/, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
Any static assets, like images, can be placed in the public/ directory.
All commands are run from the root of the project, from a terminal:
| Command | Action |
|---|---|
npm install |
Installs dependencies |
npm run dev |
Starts local dev server at localhost:4321 |
npm run build |
Build your production site to ./dist/ |
npm run preview |
Preview your build locally, before deploying |
npm run astro ... |
Run CLI commands like astro add, astro check |
npm run astro --help |
Get help using the Astro CLI |
Check out our documentation or jump into our Discord server.
This theme is based off of the lovely Bear Blog.
