link2json

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

Simple wrapper using colly to extract webpage metadata and export it as JSON. Only parses items defined in the the opengraph spec.

Todo

  • Test cases ( May be :) )

Dependencies

Depends on

  • gocolly/colly
  • patrickmn/go-cache
  • sirupsen/logrus

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// LINK2JSON_DEBUG enables or disables debug logging.
	LINK2JSON_DEBUG bool
)

Functions

func ParsePage

func ParsePage(url string)

ParsePage is a placeholder for future functionality. Currently, it does nothing.

Types

type MetaDataResponseItem

type MetaDataResponseItem struct {
	Title       string     `json:"title"`
	Description string     `json:"description"`
	Images      []WebImage `json:"images"`
	Sitename    string     `json:"sitename"`
	Favicon     string     `json:"favicon"`
	Duration    int        `json:"duration"`
	Domain      string     `json:"domain"`
	URL         string     `json:"url"`
}

func GetMetadata

func GetMetadata(targetURL string) (*MetaDataResponseItem, error)

GetMetadata fetches and returns metadata for the given URL. It first attempts to use Colly for scraping. If Colly fails to extract sufficient metadata, it falls back to Chromedp. Domains requiring Chromedp are cached for future requests.

type WebImage

type WebImage struct {
	URL    string `json:"url"`
	Alt    string `json:"alt,omitempty"`
	Type   string `json:"type,omitempty"`
	Width  int    `json:"width,omitempty"`
	Height int    `json:"height,omitempty"`
}

Jump to

Keyboard shortcuts

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