Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting file contents into post #2201

Closed
pirtleshell opened this issue Oct 6, 2016 · 4 comments
Closed

Inserting file contents into post #2201

pirtleshell opened this issue Oct 6, 2016 · 4 comments

Comments

@pirtleshell
Copy link
Contributor

pirtleshell commented Oct 6, 2016

Is there markdown to insert the contents of a file into a post? Ideally, it would look something like

{% inject path/to/file.html %}

Similar to how you can insert into a template, how can I inject the contents of file into the current markdown file. I understand that markdown isn't for templating, but I feel like there should be a way to do this without building a whole new layout for a single post.

I'd like to do this for easy maintenance and to keep the post.md clutter-free.

@NoahDragon
Copy link
Member

I don't know if there is a way for markdown, but for the theme template, we could use the <%- partial('path/to/file') %> to insert a whole file.

@pirtleshell
Copy link
Contributor Author

Yes, but to include a bit of external code in a post, one would have to essentially copy the existing layout into a new layout with the partial inserted where it belongs. What I'm thinking of is the desire to have the post look identical to all the other posts, but simply include some HMTL from an external file. Essentially like <% include_code filename.bar %> that injects the actual contents of filename.bar into the post rather than inserting the code into a codeblock. It would be useful if you had some nifty widget or a pre-written html document you wanted in the body of your post.

I'm just curious if something like this exists or if people think it maybe should..

@unnamed42
Copy link

Maybe you need include_code, one of the default tag plugins.
See https://hexo.io/docs/tag-plugins.html#Include-Code
But this will result in a <pre><code> block, cannot be used as a html inserter.

@pirtleshell
Copy link
Contributor Author

I created a plugin with the functionality to include arbitrary code and text files directly into the content of the page/post.

https://github.com/pipirt/hexo-include

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants