Combining HTML files

I want to merge one HTML file into another. Not just turn it on, but combine it.

Example

master.html:

<!DOCTYPE html> <html> <head> <title>My cat</title> </head> <body> <h1>My cat is awesome!</h1> </body> </html> 

_index.html:

 <!DOCTYPE html> <html> <body> <p><img src="cat.jpg"/></p> </body> </html> 

Now I am combining _index.html into master.html.

 $ html_merge master.html _index.html > result.html 

result.html

 <!DOCTYPE html> <html> <head> <title>My cat</title> </head> <body> <h1>My cat is awesome!</h1> <p><img src="cat.jpg"/></p> </body> </html> 

html_merge is a script what I am looking for. I will use it to create static websites.

I would like to use Ruby, but this is not required.

Update

I do not want to invent another template language. There are many template languages ​​with include / yield and partial file support. Liquid , mustache and so on, I use them for different tasks. Now I need to combine the HTML files, nothing more.

+4
source share
4 answers

Can this help? (This is in Java, though ...)

http://www.javaworld.com/javaworld/jw-07-2007/jw-07-xmlmerge.html

+1
source

Think about how such a script will look, and specifically, how you will need to write separate html files so that they can be merged. How would you tie the knots? by named divs? ensuring that each one has a parallel structure?

0
source

Performing such a merge requires knowledge of the content, which sounds to me as if you need to use a template system that can create static pages.

I used http://www.cheetahtemplate.org/ for some projects, but this may be a little redundant for your needs.

0
source

This looks great like the layout / template relationship in Rails. Although this may seem a little heavy, it will allow you to have a layout with which you want to merge the contents:

application.html.erb

 <html> <head></head> <body> Some content before hand. <%= yield %> Some content "after hand" </body> </html> 

index.html.erb

 <strong>This is my cat: <%= image_tag "cat.jpg" %></strong>. 

If you want static pages to be created from it, you can create cached versions of the page.

0
source

Source: https://habr.com/ru/post/1302862/


All Articles