Adds the ability to convert to html
Issue #14 I still want, at some point, to add to other formats but this is fine for now. The tool uses pandoc to do the conversion from md to html A sample template (without any styling) is provided. This can be overwritten in $HOME/.config/kb/templates/main.html or in the knowledgebase directory under `templates`.
This commit is contained in:
		
							parent
							
								
									4c891efdce
								
							
						
					
					
						commit
						7d554d5326
					
				
					 4 changed files with 47 additions and 3 deletions
				
			
		
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -9,6 +9,8 @@ install:
 | 
			
		|||
	mkdir -p $(DESTDIR)$(PREFIX)/bin
 | 
			
		||||
	sed '/^source/d' inc/* kb > $(DESTDIR)$(PREFIX)/bin/kb
 | 
			
		||||
	chmod +x $(DESTDIR)$(PREFIX)/bin/kb
 | 
			
		||||
	mkdir -p $(DESTDIR)$(PREFIX)/share/kb
 | 
			
		||||
	cp -r templates $(DESTDIR)$(PREFIX)/share/kb
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uninstall:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										28
									
								
								inc/to-html
									
										
									
									
									
								
							
							
						
						
									
										28
									
								
								inc/to-html
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -31,6 +31,30 @@ generate-html-toc(){
 | 
			
		|||
 | 
			
		||||
to-html(){
 | 
			
		||||
	local destination="$1"
 | 
			
		||||
	local toc="$(generate-html-toc)"
 | 
			
		||||
	echo "$toc"
 | 
			
		||||
	local preTemplate="/usr/local/share/kb/templates/main.html"
 | 
			
		||||
	local tocFile="$(mktemp)"
 | 
			
		||||
	local templateFile="$(mktemp)"
 | 
			
		||||
	generate-html-toc > "$tocFile"
 | 
			
		||||
 | 
			
		||||
	# If there is a template in the users .local/share directory, use that
 | 
			
		||||
	[ -e "${XDG_CONFIG_HOME:-$HOME/.config}/kb/templates/main.html" ] &&
 | 
			
		||||
		preTemplate="${XDG_CONFIG_HOME:-$HOME/.config}/kb/templates/main.html"
 | 
			
		||||
 | 
			
		||||
	# If there is a template in the data directory, use that
 | 
			
		||||
	[ -e "${dataDir}templates/main.html" ] &&
 | 
			
		||||
		preTemplate="${dataDir}templates/main.html"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	sed "s#\#TOC\##\${ $tocFile() }#" "$preTemplate" > "$templateFile"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	find "$dataDir" -name "*.md" | while read file; do
 | 
			
		||||
		local newFile="${file##*/}"
 | 
			
		||||
		newFile="${newFile/.md/.html}"
 | 
			
		||||
		sed -E 's/\.md( *)\)/.html\1\)/' "$file" |
 | 
			
		||||
		pandoc -f markdown -t html --template "$templateFile" > "$destination/$newFile"
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
	rm "$tocFile" "$templateFile"
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								kb
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								kb
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -22,7 +22,7 @@ WHITE='\033[1;37m'
 | 
			
		|||
NC='\033[0m'
 | 
			
		||||
 | 
			
		||||
# Provide a variable with the location of this script.
 | 
			
		||||
#scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
			
		||||
scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
			
		||||
 | 
			
		||||
# Source files
 | 
			
		||||
# ##################################################
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										18
									
								
								templates/main.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								templates/main.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="en">
 | 
			
		||||
<head>
 | 
			
		||||
  <meta charset="utf-8" />
 | 
			
		||||
  <meta name="generator" content="KB" />
 | 
			
		||||
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
 | 
			
		||||
$if(Tags)$
 | 
			
		||||
  <meta name="keywords" content="$for(Tags)$$Tags$, $endfor$" />
 | 
			
		||||
$endif$
 | 
			
		||||
<title>$Title$</title>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
 | 
			
		||||
#TOC#
 | 
			
		||||
 | 
			
		||||
$body$
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue