Raw contents include plugin
Today I created include_raw_contents
plugin for Hexo blogs. This plugin allows to include the raw content of any file directly into a blog post as raw html, making it useful for sharing code snippets, configuration files, or any html content without the need of copying and pasting it into Markdown file.
Example usage
Below, we will include the contents of a sample html file named 2024/02/raw-contents-plugin.html
that resides in source/_raw
directory:
*** Start of Imported HTML ***
Interesting Facts About Space
Space is incredibly vast and fascinating. Here are a few intriguing facts:
- The closest galaxy to us is the Andromeda Galaxy, and it's estimated to collide with the Milky Way in about 4 billion years.
- A day on Venus is longer than a year on Venus. It takes 243 Earth days to complete one rotation on its axis, but only 225 Earth days to complete an orbit around the Sun.
- Neutron stars are so dense that a sugar-cube-sized amount of material from one would weigh about as much as all of humanity.
*** End of Imported HTML ***
The content of the file is seamlessly integrated into this post, maintaining its original formatting and structure. This feature is particularly useful for technical posts, tutorials, and documentation where direct references to external files might be needed or an html version is already available.
Plugin code
Benefits
- Ease of Use: Placing html files in the
source/_raw
directory and use theinclude_raw_contents
tag in posts. - Maintainability: Update html files without having to manually update each blog post in markdown.
- Versatility: Include any html-based content, from code snippets to configuration files.