make serve function
This commit is contained in:
		
							
								
								
									
										20
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,6 +1,8 @@
 | 
				
			|||||||
src := content
 | 
					src := content
 | 
				
			||||||
cache := .cache
 | 
					cache := .cache
 | 
				
			||||||
www := _site/posts
 | 
					www_root := _site
 | 
				
			||||||
 | 
					www := $(www_root)/posts
 | 
				
			||||||
 | 
					post_index := $(www_root)/posts.html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
post_compiler := src/webcc.ml
 | 
					post_compiler := src/webcc.ml
 | 
				
			||||||
builddir := _build/default
 | 
					builddir := _build/default
 | 
				
			||||||
@@ -10,7 +12,9 @@ POSTCC := $(builddir)/$(patsubst %.ml,%.exe,$(post_compiler))
 | 
				
			|||||||
post-sources := $(shell find $(src)/ -type f)
 | 
					post-sources := $(shell find $(src)/ -type f)
 | 
				
			||||||
post-htmls   := $(patsubst $(src)/%.md,$(www)/%.html,$(post-sources))
 | 
					post-htmls   := $(patsubst $(src)/%.md,$(www)/%.html,$(post-sources))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
all: $(POSTCC) $(post-htmls)
 | 
					.PHONY: all serve clean $(post_index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					all: $(POSTCC) $(post-htmls) $(post_index) $(www_root)/static
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(www):
 | 
					$(www):
 | 
				
			||||||
	mkdir -p $(www)
 | 
						mkdir -p $(www)
 | 
				
			||||||
@@ -18,8 +22,20 @@ $(www):
 | 
				
			|||||||
$(www)/%.html: $(src)/%.md $(www)
 | 
					$(www)/%.html: $(src)/%.md $(www)
 | 
				
			||||||
	$(POSTCC) $< -o $@
 | 
						$(POSTCC) $< -o $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# make sure that this target is .PHONY!
 | 
				
			||||||
 | 
					$(post_index):
 | 
				
			||||||
 | 
						echo LOL > $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(www_root)/static:
 | 
				
			||||||
 | 
						cp -R static $@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(POSTCC): $(post_compiler)
 | 
					$(POSTCC): $(post_compiler)
 | 
				
			||||||
	dune build
 | 
						dune build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	rm $(POSTCC)
 | 
						rm $(POSTCC)
 | 
				
			||||||
 | 
						rm -fr $(www_root)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					serve:
 | 
				
			||||||
 | 
						cd $(www_root) && python -m SimpleHTTPServer
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ let spec =
 | 
				
			|||||||
    " Consider all remaining arguments as input file names.";
 | 
					    " Consider all remaining arguments as input file names.";
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(** Utitilies *)
 | 
				
			||||||
let with_open_in fn f =
 | 
					let with_open_in fn f =
 | 
				
			||||||
  let ic = open_in fn in
 | 
					  let ic = open_in fn in
 | 
				
			||||||
  match f ic with
 | 
					  match f ic with
 | 
				
			||||||
@@ -34,6 +34,8 @@ let read_metadata ic =
 | 
				
			|||||||
    | _ -> lst
 | 
					    | _ -> lst
 | 
				
			||||||
  in go []
 | 
					  in go []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(** Functions for processing an individual post *)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let format_post ~title ~tags ~date ~contents =
 | 
					let format_post ~title ~tags ~date ~contents =
 | 
				
			||||||
  String.concat "" [
 | 
					  String.concat "" [
 | 
				
			||||||
{|<!DOCTYPE html>
 | 
					{|<!DOCTYPE html>
 | 
				
			||||||
@@ -69,6 +71,7 @@ let format_post ~title ~tags ~date ~contents =
 | 
				
			|||||||
</body>|}]
 | 
					</body>|}]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(* convert contents from [ic] to a post webpage, output to [oc] *)
 | 
				
			||||||
let process ic oc =
 | 
					let process ic oc =
 | 
				
			||||||
  let metadata = read_metadata ic in
 | 
					  let metadata = read_metadata ic in
 | 
				
			||||||
  let lookup_metadata k =
 | 
					  let lookup_metadata k =
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user