diff --git a/parse.scm b/parse.scm index 54cea99..b238ce7 100644 --- a/parse.scm +++ b/parse.scm @@ -65,3 +65,13 @@ (lambda (recipes search-ingredients) (filter (lambda (x) (contains-ingredients? x search-ingredients)) recipes))) + +(define recipe-by-name + (lambda (recipes name) + (if (null? recipes) + #f + (let ((recipe (car recipes))) + (if (equal? (title recipe) + name) + recipe + (recipe-by-name (cdr recipes) name)))))) diff --git a/web/server.rb b/web/server.rb index 747652b..032592a 100644 --- a/web/server.rb +++ b/web/server.rb @@ -6,8 +6,12 @@ get '/' do `cd ..; echo "(display (html-wrap (cookbook-as-html cookbook)))" | petite -q "batch.scm"` end -get '/:ingredient' do +get '/ingredient/:ingredient' do ingredient = HTMLEntities.new.decode params['ingredient'] - puts ingredient `cd ..; echo "(display (html-wrap (cookbook-as-html (recipes-by-ingredients cookbook '(\\"#{ingredient}\\")))))" | petite -q "batch.scm"` end + +get '/recipe/:title' do + title = HTMLEntities.new.decode params['title'] + `cd ..; echo "(display (html-wrap (recipe-as-html (recipe-by-name cookbook \\"#{title}\\"))))" | petite -q "batch.scm"` +end