model

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateRating

type AggregateRating struct {
	ReviewCount int     `json:"reviewCount,omitempty"`
	RatingCount int     `json:"ratingCount,omitempty"`
	RatingValue float64 `json:"ratingValue,omitempty"`
	BestRating  int     `json:"bestRating,omitempty"`
	WorstRating int     `json:"worstRating,omitempty"`
}

AggregateRating represents the average rating based on multiple ratings or reviews https://schema.org/AggregateRating

type DataInput

type DataInput struct {
	Url      string
	Text     string
	RootNode *html.Node           `json:"-"`
	Document *goquery.Document    `json:"-"`
	Schemas  *microdata.Microdata `json:"-"`
}

DataInput represents the input data for the scraper

type Feed added in v0.9.0

type Feed struct {
	Url     string    `json:"url"`
	Entries []*Recipe `json:"entries"`
}

Feed represents a list of recipes found on a page or in a feed

func (*Feed) AddEntry added in v0.9.0

func (f *Feed) AddEntry(entry *Recipe) bool

AddEntry adds a recipe to the feed if it does not already exist

func (*Feed) String added in v0.9.0

func (f *Feed) String() string

type FeedOptions added in v0.9.0

type FeedOptions struct {
	// When true, only the feed will be scraped, without scraping each entry's url
	Quick bool
	// Filter out recipes with fewer than this number of ingredients (0 = no filter)
	MinIngredients int
	// When true, filter out recipes without an image
	RequireImage bool
	// When true, filter out recipes without instructions
	RequireInstructions bool
}

FeedOptions options for feed scraping

type FeedScraper added in v0.9.0

type FeedScraper = func(data *DataInput, feed *Feed) error

FeedScraper defines a function that returns a feed from the input data

type HowToSection

type HowToSection struct {
	HowToStep              // because it's optional to have a group, we have to embed `HowToStep` here
	Steps     []*HowToStep `json:"itemListElement,omitempty"`
}

HowToSection a group of steps in the instructions https://schema.org/HowToSection

type HowToStep

type HowToStep struct {
	Name  string `json:"name,omitempty"`
	Text  string `json:"text,omitempty"`
	Url   string `json:"url,omitempty"`
	Image string `json:"image,omitempty"`
	Video string `json:"video,omitempty"`
}

HowToStep a step in the instructions https://schema.org/HowToStep

type ImageObject

type ImageObject struct {
	Url     string `json:"url,omitempty"`
	Width   int    `json:"width,omitempty"`
	Height  int    `json:"height,omitempty"`
	Caption string `json:"caption,omitempty"`
}

ImageObject represents an image object https://schema.org/ImageObject

type InputOptions

type InputOptions struct {
	SkipUrl    bool
	SkipText   bool
	SkipSchema bool
}

InputOptions options for pre-processing input

type NutritionInformation

type NutritionInformation struct {
	ServingSize           string  `json:"servingSize,omitempty"`           // The serving size, in terms of the number of volume or mass.
	Calories              float64 `json:"calories,omitempty"`              // The number of calories.
	CarbohydrateContent   float64 `json:"carbohydrateContent,omitempty"`   // The number of grams of carbohydrates.
	CholesterolContent    float64 `json:"cholesterolContent,omitempty"`    // The number of milligrams of cholesterol.
	FatContent            float64 `json:"fatContent,omitempty"`            // The number of grams of fat.
	FiberContent          float64 `json:"fiberContent,omitempty"`          // The number of grams of fiber.
	ProteinContent        float64 `json:"proteinContent,omitempty"`        // The number of grams of protein.
	SaturatedFatContent   float64 `json:"saturatedFatContent,omitempty"`   // The number of grams of saturated fat.
	SodiumContent         float64 `json:"sodiumContent,omitempty"`         // The number of milligrams of sodium.
	SugarContent          float64 `json:"sugarContent,omitempty"`          // The number of grams of sugar.
	TransFatContent       float64 `json:"transFatContent,omitempty"`       // The number of grams of trans fat.
	UnsaturatedFatContent float64 `json:"unsaturatedFatContent,omitempty"` // The number of grams of unsaturated fat.
}

NutritionInformation according to https://schema.org/NutritionInformation

type Organization

type Organization struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Url         string `json:"url,omitempty"`
}

Organization according to https://schema.org/Organization

type Person

type Person struct {
	Name        string   `json:"name,omitempty"`
	JobTitle    string   `json:"jobTitle,omitempty"`
	Description string   `json:"description,omitempty"`
	KnowsAbout  []string `json:"knowsAbout,omitempty"`
	Url         string   `json:"url,omitempty"`
	Image       string   `json:"image,omitempty"`
}

Person according to https://schema.org/Person

type Recipe

type Recipe struct {
	Url           string                `json:"url,omitempty"`
	Name          string                `json:"name,omitempty"`
	Description   string                `json:"description,omitempty"`
	Language      string                `json:"inLanguage,omitempty"`
	Images        []*ImageObject        `json:"image,omitempty"`
	Author        *Person               `json:"author,omitempty"`
	Publisher     *Organization         `json:"publisher,omitempty"`
	Text          string                `json:"text,omitempty"`
	PrepTime      string                `json:"prepTime,omitempty"`
	CookTime      string                `json:"cookTime,omitempty"`
	TotalTime     string                `json:"totalTime,omitempty"`
	Difficulty    string                `json:"educationalLevel,omitempty"` // FIXME: `difficulty` is not a part of Recipe schema https://github.com/schemaorg/schemaorg/issues/3130
	CookingMethod string                `json:"cookingMethod,omitempty"`
	Diets         []string              `json:"suitableForDiet,omitempty"`
	Categories    []string              `json:"recipeCategory,omitempty"`
	Cuisines      []string              `json:"recipeCuisine,omitempty"`
	Keywords      []string              `json:"keywords,omitempty"`
	Yield         string                `json:"recipeYield,omitempty"`        // alias `yield`
	Ingredients   []string              `json:"recipeIngredient,omitempty"`   // alias `supply`
	Equipment     []string              `json:"tool,omitempty"`               // FIXME: `recipeEquipment` is not a part of Recipe schema https://github.com/schemaorg/schemaorg/issues/3132
	Instructions  []*HowToSection       `json:"recipeInstructions,omitempty"` // alias `step`
	Nutrition     *NutritionInformation `json:"nutrition,omitempty"`
	Rating        *AggregateRating      `json:"aggregateRating,omitempty"`
	CommentCount  int                   `json:"commentCount,omitempty"`
	Video         *VideoObject          `json:"video,omitempty"`
	Links         []string              `json:"sameAs,omitempty"` // maybe not the cleanest name, but we can store additional links here
	DateModified  *time.Time            `json:"dateModified,omitempty"`
	DatePublished *time.Time            `json:"datePublished,omitempty"`
}

Recipe is the basic struct for the recipe https://schema.org/Recipe Perhaps, I would rename recipeYield, recipeIngredient, recipeInstructions to their aliases, but many websites expect only these names (like Google Search https://developers.google.com/search/docs/appearance/structured-data/recipe)

func (*Recipe) AddImage

func (r *Recipe) AddImage(image *ImageObject)

func (*Recipe) AddImageUrl

func (r *Recipe) AddImageUrl(imageUrl string)

func (*Recipe) IsEmpty added in v0.9.0

func (r *Recipe) IsEmpty() bool

func (*Recipe) IsValid added in v0.9.0

func (r *Recipe) IsValid() bool

func (*Recipe) String

func (r *Recipe) String() string

type Scraper

type Scraper = func(data *DataInput, recipe *Recipe) error

Scraper defines a function that fill a recipe from the input data

type VideoObject

type VideoObject struct {
	Name         string     `json:"name,omitempty"`
	Description  string     `json:"description,omitempty"`
	Duration     string     `json:"duration,omitempty"`
	EmbedUrl     string     `json:"embedUrl,omitempty"`
	ContentUrl   string     `json:"contentUrl,omitempty"`
	ThumbnailUrl string     `json:"thumbnailUrl,omitempty"`
	UploadDate   *time.Time `json:"uploadDate,omitempty"`
}

VideoObject represents a video object https://schema.org/VideoObject

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL