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
IBlogPostProcessorServicehandles processing of html, yaml and json files. - The
ProcessPostAsyncandProcessPostMetadataAsyncprocesses posts and metadata files respectively. - The
ProcessPostsMetadataAsyncfetches theMetadata.jsonfile and caches it in a global static variable namedGlobalVariables.YamlMetadata.
- The
Blogpage has theBlogPostscomponents which renders all the posts by injecting theIBlogPostProcessorServiceservice and fetching theMetadata.jsonfile by callingProcessPostsMetadataAsync. - The
Postpage renders a specific post by injectingIBlogPostProcessorServiceservice and fetching the post related files by callingProcessPostAsync. The files are deserialized to aBlogPostDocumenttype which has aMarkdown,htmlandYamlproperties.
- The
BlogPostcomponent renders the blog post cards in theBlogpage. - The
ProjectCardscomponent renders my GitHub repositories as cards using the GitHub API and it calls theIntersection Observeron initialization using theIJSRuntimein 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
MarkdownCompileris 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
Blogdirectory (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
Sitedirectory. - Construct the
Metadata.jsonfile that represents the posts' metadata. - Any exceptions are logged to
ExecuteLog.login the assembly directory.
- Robots.txt and Sitemap.xml are generated automatically with the MarkdownCompiler via the
Seoclass. - The process checks for a
NoListproperty 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
XmlDocumentclass. - 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