This episode is for members only

Sign up to access "Build A Static File Blog with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
05. Changing the parser for added detail

Transcript

00:00
So as we saw before, when we dumped out each of these posts,
00:03
we're a little thin on any of the attributes that we've already created, like the title over here. And we're going to be including quite a few of these, as well as tags and things like that.
00:13
And you can include pretty much anything you want in here. There's no limit. So how do we get this information? Well, we need to come over to our sheets config again,
00:22
where we spoke about our content parser. At the moment, we're working with a markdown parser, but this package also includes an additional parser, which allows us to add in these attributes at the top.
00:35
Now, this parser is called markdown with front matter parser. So this will read in these initial things, these initial attributes that we want to use, and it will include them as well.
00:48
So if we take a look at this here, you can see that we get this yaml front matter parser, which parses the contents and includes them inside of here as well. Like this.
00:58
So we get them attributes merged in, as well as the contents of our blog post. So now that we've switched that parser over and we give that a refresh,
01:09
notice that the title has now rolled in and there's no limit to what we add here. There are some structural rules that we need to follow, but we can just start to add in any of this content now.
01:21
Now, I guess the downside of creating a blog like this is you're going to have to make sure the structure is the same for each of your blog posts. It's not like a database schema
01:30
where everything is predefined out for you and you have to insert specific rows and columns. It doesn't really work like that. So we're just going to have to make sure each of these is the same.
01:41
So let's start with the building a blog in Laravel and let's just go and fill in what we think we're going to need. So the title is going to be building a blog with Laravel. We're going to have a author in here as well.
01:55
So I'm just going to set that to myself. We're going to have a teaser in here. Now I'm going to go ahead and copy over some Lipsum, Lorem Ipsum that I already have in here.
02:06
But of course, feel free to generate that. And I think for now that's pretty much it. So we can just kind of stick with that for now. We'll do the same thing for another blog post
02:14
just so we have something else to deal with as well. So let's say another blog post, same author. And for the teaser here, we'll switch this out as well. In fact, let's just leave it the same.
02:26
It doesn't really matter too much. So now when we come over, we have access to each of these items that we have put in there. Of course, we can prove that by just dumping this out.
02:37
And we've got all that information in here. So we're just going to access them like normal attributes. So the first thing is going to be the title. So let's get rid of that slug in there as well.
02:47
And so she pulled this down a little bit to keep this neat. And inside of the anchor, let's output the post title. And we can output the teaser here as well. So post and teaser.
03:01
And we should be good. There we go. We've got a really nice listing now of all of that information. OK, so let's jump over to add in some more information here,
03:11
like the author at the bottom. And then later on, we're going to get to the tags. So just underneath the teaser, let's create out a div here with text small.
03:20
We're going to modify this. So prose doesn't interfere too much with it. Because we don't want this to be the same size. And we'll set a margin top of 10.
03:28
And then we'll just go ahead and output the post author. Like I said, we're going to be adding a little bit more information to this later. So there is the author for each of our blog posts.
03:37
Now, just next to this, we want the post date. So let's go ahead and grab the post date out. Remember, this comes through as a carbon instance. So now what we can do is start to chain on
03:49
any of the methods that we have available with carbon. For example, we could say to date string. That would be more appropriate. And that just gives us out the date in this format.
04:00
You can format this in any way you want. You could even leave it as the default, which will just render out something like this, which doesn't really make too much sense.
04:07
So you can go ahead and change that up to do whatever you want to do. You could even use the diff for humans method on here. And that would give you out when this was created.
04:17
So one week from now, because we added the date in a little bit too late, but we have one month to go for this one. So I'm going to leave this for as to date string.
04:27
And I think here we are pretty much done. So just by switching over that parser, which we had a little look into under sheets, that is now giving us the ability to add in
04:40
any items here that you need. So you can just add more if there's something else that you need to include with each of your blog posts.
13 episodes1 hr 11 mins

Overview

Let's build a ridiculously fast blog from scratch in Laravel, entirely driven by markdown files. No database required!

Your blog will feature everything you're used to, like syntax highlighting, post tagging and pagination. Plus, it'll render in record time.

Once you're done with the course, you'll be able to add on additional features with ease, style it up how you want and quickly create new posts since there's no need for an admin panel.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.