I have this:
#!/bin/bash
# Open up the document
read -d '' html <<- EOF
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<meta name="...">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
EOF
#Overwrite the old file with a new one
echo "$html" > index.html
# Convert markdown to HTML
`cat README.md | marked --gfm >> index.html`
# Put the converted markdown into the HTML
read -d '' html <<- EOF
</body>
</html>
EOF
# Save the file
echo "$html" >> index.html
But what I’d like is a single write instead Basically, in the first EOF i’d have the </html></body> too, and in between the <body> tags I’d have like {{CONTENT}} to be replaced with cat README.md | marked --gfm like:
read -d '' html <<- EOF
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<meta name="...">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
{{CONTENT}}
</body>
</html>
EOF
I tried over and over with the sed command, but I think I’m doing something wrong and I read there’s issues when the file contents to search thru have slashes in it. How could I implement the sed command here?
I think you can do this using a single call to
cat, using command substitution to insert the read-me in the middle:Another option might be to use
printf, replacing the {{CONTENT}} placeholder with a simple format string.