Git Product home page Git Product logo

Comments (3)

satnaing avatar satnaing commented on July 24, 2024 2

Hello @SahilFruitwala!
You can you AstroPaper with any Headless CMS. However, AstroPaper is developed with file-system-based contents in mind. I've written a blog post about using AstroPaper with git-based HeadlessCMS.

In order to connect AstroPaper with an API-driven CMS, you have to update the data fetching logic.
For example:

// From this
const posts = await Astro.glob<Frontmatter>("../contents/**/*.md");

// To this
const response = await fetch("https://your-cms-url.com/posts");
const posts = await response.json();

Besides, you might have to replace frontmatter properties with your API data.
For example, if your API response is something like this,

[
  {
  "userId": 1,
  "id": 1,
  "slug": "some-dummy-post",
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
  },
  // some more data
]

You need to update the post displaying code too.

// from this
sortedPosts.map(
  ({ frontmatter }, index) =>
    index < 4 && (
      <Card
        href={`/posts/${slugify(frontmatter)}`}
        post={frontmatter}
        secHeading={false}
      />
    )
)

// to this
sortedPosts.map(
  (post, index) =>
    index < 4 && (
      <Card
        href={`/posts/${slugger(post.slug)}`}
        post={post}
        secHeading={false}
      />
    )
)

from astro-paper.

SahilFruitwala avatar SahilFruitwala commented on July 24, 2024

Got it Thanks. 🙌🏼

from astro-paper.

AustinSaysHello avatar AustinSaysHello commented on July 24, 2024

@SahilFruitwala did you ever get it to work with the CMS? Curious to see if you had to make any additional changes

from astro-paper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.