瀏覽代碼

Add LitK author data. TG-2

Tati 7 年之前
父節點
當前提交
601ba5f6e0
共有 2 個文件被更改,包括 15 次插入1 次删除
  1. 8 0
      ktchn/src/recipes/index.ts
  2. 7 1
      ktchn/src/recipes/scrape.ts

+ 8 - 0
ktchn/src/recipes/index.ts

@@ -38,20 +38,28 @@ export class RecipeDetails {
     }
 }
 
+export interface Author {
+  name: string,
+  website?: string,
+}
+
 export class Recipe {
   public name: string;
   tags!: string[];
   ingredients!: ComposedIngredients[];
   details!: RecipeDetails;
   instructions!: string[];
+  author: Author;
 
   constructor(
     name: string,
+    author: Author,
     details?: RecipeDetails,
     ingredients?: ComposedIngredients[],
     instructions?: string[],
   ) {
     this.name = name;
+    this.author = author;
     this.details = details || new RecipeDetails();
     this.ingredients = ingredients || [];
     this.instructions = instructions || [];

+ 7 - 1
ktchn/src/recipes/scrape.ts

@@ -1,6 +1,6 @@
 import RequestPromise from "request-promise";
 import Cheerio from "cheerio";
-import { Recipe, RecipeDetails, Ingredient, ComposedIngredients } from './index';
+import { Recipe, RecipeDetails, Ingredient, ComposedIngredients, Author } from './index';
 import { parse } from "recipe-ingredient-parser";
 
 type RegexMutator = (s: RegExpMatchArray) => number;
@@ -19,6 +19,11 @@ const parseTime = (data: string) => {
   return parsedHoursAsMin + parsedMinutes;
 };
 
+const LAURA_DATA: Author = {
+  name: 'Laura in the Kitchen',
+  website: 'http://www.laurainthekitchen.com',
+};
+
 const LAURA_MAP: {
   [index:string] : {
     key: string,
@@ -98,6 +103,7 @@ function getInstructions($:CheerioSelector): string[] {
 function lauraInTheKitchen($:CheerioSelector):Recipe {
   let recipe = new Recipe(
     getRecipeName($),
+    LAURA_DATA,
     getRecipeDetails($),
     getIngredients($),
     getInstructions($),