33
loading...
This website collects cookies to deliver better user experience
git
.git
!Our go-to content solutions:@NetlifyCMS for internal projects (when we just need it to work)@forestryio for client projects (when a clean, user friendly UI is a must)@fauna (when a file based CMS just won't cut it)
What tools are you always reaching for?
netlify-cms
library from CDN, but as mentioned in the docs, you can install from NPM instead. In that case, Snowpack will handle bundling the JS in production builds./admin/index.html
and /admin/config.yml
, you can simply copy those files from the docs to your Astro project's /public
folder. Astro includes everything in the /public
directory as static assets, for example your /public/admin/index.html
file will be available when navigating to yoursite.com/admin
.config.yml
is pointing to the correct folder.collections:
# Our blog posts
- name: "blog" # Used in routes, e.g., /admin/collections/blog
label: "Post" # Used in the UI
folder: "src/pages/posts" # The path to the folder where the documents are stored
create: true # Allow users to create new documents in this collection
slug: "{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
fields: # The fields for each document, usually in front matter
- { label: "Title", name: "title", widget: "string" }
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Author", name: "author", widget: "string", default: "Anonymous" }
- { label: "Summary", name: "summary", widget: "text" }
- { label: "Tags", name: "tags", widget: "list", default: ["post"] }
- { label: "Body", name: "body", widget: "markdown" }
config.yml
, note that folder
is pointing to the correct directory.export let collection: any;
export async function createCollection() {
return {
/** Load posts, sort newest -> oldest */
async data() {
const allPosts = Astro.fetchContent('./posts/*.md');
return allPosts
.sort((a, b) => new Date(b.date) - new Date(a.date));
},
/** Set page size */
pageSize: 10,
}
}
fetchContent
API takes care of loading all matching markdown files. I left out RSS feed support here for brevity, but you can find that in the demo repo here.<Layout title={title} description={description}>
<h1>{title}</h1>
{collection.data.map((post) => (
<PostPreview post={post} />
))}
</Layout>
$blog.astro
template is taking the data loaded above and rendering a list of post previews. If you have experience with React (or JSX) this will feel very familiar. Brackets {}
are used to escape plain old JS into the template, mapping over the posts loaded in data()
and passing the data of to the PostPreview
component./author/:id
or /tags/:tag
routes for now, but keep an eye out for a follow-up blog post once the routing APIs are finalized!