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:
cat << EOF > index.html
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<meta name="...">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
$(marked --gfm < README.md)
</body>
</html>
EOF
Another option might be to use printf, replacing the {{CONTENT}} placeholder with a simple format string.
read -d '' -r template <<EOF
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<meta name="...">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
%s
</body>
</html>
EOF
printf "$template" "$(marked --gfm < README.md)"
You wouldn't.
md="$(marked --gfm <README.md)"
> index.html
while read html
do
echo "${html/{{CONTENT}}/$md}" >> index.html
done <<- EOF
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<meta name="...">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
{{CONTENT}}
</body>
</html>
EOF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With