The code in this repository is not meant to be a theme template nor cloned or deployed, its for my own personal use, if it helps you, feel free to take whatever inspiration you want from it.
As part of my process to learn Blazor Web Assembly, i will be creating a static blog that takes posts as markdown files with yaml metadata and output .html + .yml files for every post and display them dynamically.
The solution consists of two projects:
The main blazor wasm app, it contains all the logic and components to form the website.
The blog is located in wwwroot
and structured like this:
- Blog
- Metadata
- Posts
- Site
The Metadata
directory has a Metadata.json
file that contains all the posts' metadata which is constructed by the MarkdownCompiler
project.
The purpose of the Metadata.json
file is to bypass the limitation of enumerating over files in wwwroot
, it contains all the user provided posts' metadata: Title
, Dates
, Tags
, etc.
The Posts
directory contains the markdown files that'll be compiled to .html
and .yml
on build via the MarkdownCompiler
project.
The Site
directory contains the compilation output of the MarkdownCompiler
project .html
and .yml
files for every post.
- The
IBlogPostProcessorService
handles processing of html, yaml and json files. - The
ProcessPostAsync
andProcessPostMetadataAsync
processes posts and metadata files respectively. - The
ProcessPostsMetadataAsync
fetches theMetadata.json
file and caches it in a global static variable namedGlobalVariables.YamlMetadata
.
- The
Blog
page has theBlogPosts
components which renders all the posts by injecting theIBlogPostProcessorService
service and fetching theMetadata.json
file by callingProcessPostsMetadataAsync
. - The
Post
page renders a specific post by injectingIBlogPostProcessorService
service and fetching the post related files by callingProcessPostAsync
. The files are deserialized to aBlogPostDocument
type which has aMarkdown
,html
andYaml
properties.
- The
BlogPost
component renders the blog post cards in theBlog
page. - The
ProjectCards
component renders my GitHub repositories as cards using the GitHub API and it calls theIntersection Observer
on initialization using theIJSRuntime
in order to call the API once the component is in the viewport and it caches the received data in the static global variableGlobalVariables.GitHubData
.
- The
MarkdownCompiler
is the project responsible for compiling the markdown files. - The project is triggered to run on every build as a Visual Studio post build event.
- Performs clean up on the
Blog
directory (if it exists) to clear it from old posts and metadata files so it can start compiling the files again. - Create the blog structure in the main project if it's not created.
- Parse markdown files that also consists of yaml markup, separate them into compiled html and yml files and write them to the
Site
directory. - Construct the
Metadata.json
file that represents the posts' metadata. - Any exceptions are logged to
ExecuteLog.log
in the assembly directory.
- Robots.txt and Sitemap.xml are generated automatically with the MarkdownCompiler via the
Seo
class. - The process checks for a
NoList
property on posts' metadata in order to decide if it should be added to Robots.txt or not. - Sitemap.xml is generated using the same json metadata via the
XmlDocument
class. - Static pages are hardcoded in both files.
- Markdig for markdown compilation.
- YamlDotNet for yaml related operations.
- jQuery.
- PrismJs for syntax highlighting.
- Line Awesome icon font.
- Brotli for blazor file decompression.
Additionally the project uses SASS.
Licensed under the GNU General Public License v3.0.
Hamzi Alsheikh
Website: https://www.hamzialsheikh.tk