Markdown mailable messages allow you to take advantage of the pre-built templates and components of mail notifications in your mailables. Since the messages are written in Markdown, Laravel is able to render beautiful, responsive HTML templates for the messages while also automatically generating a plain-text counterpart. Laravel Version: v6.10.0 PHP Version: 7.2.21 (Valet / Mac OS) Database Driver & Version: Description: Markdown parser @component('mail::panel') shows RAW HTML tags. This issue is not present in Laravel version v6.9.0 and bellow.
Recently I rebuilt my personal website with PHP laravel and Bootstrap 4. I need a simple blogging system to write some of my ideas. I examined some existing Laravel and PHP code packages. I also researched some complete blogging systems. Eventually I decided to write a simple blogging system from scratch. This article will write some of my ideas and experience in building a blogging system.
My requirements
- Must base on markdown, especially GitHub flavored markdown. I'm not saying how good the markdown format is, but many of my open source documents have been using markdown. By using a markdown based blogging system, I don't need to learn a new text format in other blog system. And I can use my blogging system for document services.
- Must be file-based and not dependent on the database. And a blog is only one file that cannot have redundant indexes and metadata files. This allows me to manage blogs with any version management system, and to ease migration.
- Must be able to integrate with Laravel.
- Must be lightweight enough.
Why Create from scratch
- A lot of independent Laravel blog code packages are either no longer maintained or not meeting my requirements.
- The full blogging system such as WordPress obviously doesn't meet my requirements.
- Even if I use a ready-made code base, adapting the code to meet my needs may take longer time than writing from scratch.
Create indexing and metadata database
Wait, doesn't it need to be completely file-based, how can there be a database? Yes, the blog content itself is file based, but for performance reasons, blog related indexes and metadata should be placed in the database. The database is only used for performance optimization. All data in the database is parsed from the blog file. That is, I can delete all data from the database and then recover the data from the markdown files. This allows the database to be used to optimize performance, rather than as a strong dependency of the blogging system. This is important, not only that the code design should be decoupled, but also that the system design should be decouple as well.
The database structure is simple, with only one table storing metadata for information such as update time, and a table that holds tag information. Other tables may be added in the future, but the principle is simple, all the data is parsed from the blog files.
Data in the database supports lazy creation. When a blog page is loaded, metadata is recreated if the system discovers that there are no related data in the database or the metadata expires.
When an article is created or deleted, the index needs to be rebuilt to allow the change reflects on the index page. The blog engine doesn't automatically detect the index change for performance reason. I just write a tool in PHP to rebuild the index. The tool is a Laravel artisan command and reuse most of the blogging code base.
Since the database data is almost read-only except the lazy creation, I first considered using SQLite. However, since there are other modules that need to use the database, MySQL was eventually chosen.
Markdown to HTML conversion
There are a lot of good enough open source markdown to HTML conversion Libraries, I finally chose Parsedown. But I need to extend it to add target= '_blank'
and rel= 'nofollow'
to external links. I also do some extra regular expression replacement to support code syntax highlighting.
Parsing markdown Files
Important blog metadata are stored in a special marker block of markdown. Before converting the markdown into HTML, the blog engine parses and extracts the metadata block and store them into the database. Metadata may be used in formats such as YAML and parsed with third-party libraries, but I decided to parse the simple format myself because it's a lot faster than finding a third-party library.
Examples of some metadata
Comment System
My requirements for a comment system Memories for mac.
- Must be able to be attached to any article. So the comment system for those full blogging systems doesn't fit.
- Must support guest comment. I found that the most satisfying PHP or Laravel comment packages requires registered users.
- Good to integrate into Laravel.
- Good to display it in a tree.
- Good anti-spam support.
After I looked at some PHP based article comment systems, I had thought to write a comment system from scratch myself. I hesitated for a long time, always feeling unworthy of reinventing a wheel, and most importantly, the comment system was not a must to have. Finally I decided to use the third party comment service, such as HTML comment box (in fact, there is Disqus, but I don't like it very much). Luckily, before I used the third-party service, I found a very good package, Commentics, which basically met my needs.
Summary
It makes a lot of sense to write a blog system based on Markdown from the beginning. In the case of not a lot of time spent, I have a blog system that fully meets my needs, and I will slowly add new features. Mac change icon for file.
Add Comment
Comments (1)
Can you show how to parse markdown metadata using parsedown? I have tried to find a resource on that and red dosumentation but haven't found anything..
It's pretty simple. Best security systems for mac.
$parsedown = new Parsedown();
Markdown Laravel Login
$html = $parsedown->text($mdText);
Markdown Laravel Blade
My code is just like that.