jamestagal / plenti-educenter

0 stars 1 forks source link

Error - Cannot read property 'date' of undefined #2

Closed jamestagal closed 2 years ago

jamestagal commented 2 years ago

Hi @jimafisk I am working away at this theme, following along with your tutorial videos up to - Plenti Bigspring: Part 15 (Truncate Text and Remove HTML from String but I am stuck at a couple of points.

  1. Firstly the property date in my post.json files might be a problem. Is it a protected word? I get the following error message.
    javascript stack trace: TypeError: Cannot read property 'date' of undefined
    at create_ssr:28:58
    at each (create_ssr:1521:16)
    at create_ssr:26:151
    at Object.$$render (create_ssr:1555:22)
    at create_ssr:27:73
    at $$render (create_ssr:1555:22)
    at Object.render (create_ssr:1563:26)
    at create_ssr:1:58 (File: /home/runner/work/plenti/plenti/cmd/build.go, Line: 144)
    Total build took 1.768640084s

    I have defined the following in the post.json files:

    "publish": {
        "date": "06 Jul, 2022",
        "text": "Date :"
    },

    Then refer to these fields in the template:

    </i> {post.fields.publish.date}</li>
  2. Posts content have a couple of attributes that are different to the Blog page. For instance, the Blog page uses two icons ; one for calendar ti-calendar and one for user ti-user that aren't included in the posts pages. How could I solve this problem? Ironically all the content and styling for the cards from Latest News section in index.json is exactly the same content and styling on the cards for the blog page. The only different is that there are fewer cards on the index page. So that begs the questions should I be aggregating the content from the blog page over to the index page?

Ben

jamestagal commented 2 years ago

Hey @jim

I think I fixed the error from above No 1 issue. And it is building again which is great! But I also updated the path overrides for the blog posts from types to routes see below but that didn't seem to work: OLD

    "types": {
        "posts":"/blog/:filename"
    },

NEW

    "routes": {
        "posts": "/blog/:filename"
    },

So on this route : http://localhost:3000/blog/post-1

I get a 404 page not found error.

Ben

jimafisk commented 2 years ago

Hi @jamestagal,

It looks like you're using the wrong key name in layouts/content/posts.svelte: https://github.com/jamestagal/plenti-educenter/blob/4cdb7d4321a322be866ca9e46dcfbe396f094b44/layouts/content/posts.svelte. You're referencing published but it should be publish. When I make this change locally it works on my end:

blog-post-1

Hope that helps!

jamestagal commented 2 years ago

oh yes...Thanks @jimafisk I have to remember to change the name in the svelte file as well as in the json.