antidote

package module
v0.0.0-...-215acae Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: MIT Imports: 11 Imported by: 0

README

Antidote

Antidote crawls a web page and 'cures' the HTML by loading assets (CSS, JS, images) directly into the DOM.

The effect is that the final HTML will have zero external HTTP calls on page load.

Usage

Getting cured HTML
a := antidote.New()
a.Mix(&antidote.Ingredients{URL: "https://www.website.com"})

html, err := a.Cure()
if err != nil {
	log.Fatal(err)
}
Getting cured HTML and saving it for later
a := antidote.New()
a.Mix(&antidote.Ingredients{URL: "https://www.website.com"})

if _, err := a.Cure() != nil {
	log.Fatal(err)
}

// `a.Html()` will contain the cured HTML. Use at your leisure.
Saving the HTML to a file
a := antidote.New()
a.Mix(&antidote.Ingredients{URL: "http://www.website.com"})

html, err := a.Cure()
if err != nil {
	log.Fatal(err)
}

f, err := os.OpenFile("./website.html", os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
	log.Fatal(err)
}

f.Write([]byte(html))

What works

  • Convert CSS assets to raw source
<!-- This -->
<link rel="stylesheet" href="foo.com/bar.css" />

<!-- To this -->
<style>
    // Raw CSS here...
</style>
  • Convert JS assets to raw source
<!-- This -->
<script src="foo.com/bar.js"></script>

<!-- To this -->
<script>
    // Raw JS here...
</script>
  • Convert image src values to base64 data URL's
<!-- This -->
<img src="foo.com/bar.png" />

<!-- To this -->
<img src="data:image/png;base64,abcd..." />

TODO

  • Convert CSS property URL's to base64 data URL's
<!-- This -->
<style>
    body {
        background-image: url(../foo/bar.png);
    }
</style>

<!-- To this -->
<style>
    body {
        background-image: url(data:image/png;base64,abcd...);
    }
</style>

Contributing

In general, this project follows the "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "master" before making a pull request!

Licensing

Antidote is licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Antidote

type Antidote struct {
	// contains filtered or unexported fields
}

Antidote object provides the APi operation methods for curing a site.

func New

func New() *Antidote

New creates a new instance of an Antidote pointer.

func (*Antidote) Cure

func (a *Antidote) Cure() (string, error)

Cure will begin running the algorithms to cure a websites source of any CORS restrictions enforced by browsers.

func (*Antidote) Html

func (a *Antidote) Html() string

Html retrieves the cured HTML (it will be empty if called before Antidote.Cure() has been called).

func (*Antidote) Mix

func (a *Antidote) Mix(ingredients *Ingredients)

Mix sets the options of Antidote.

type Ingredients

type Ingredients struct {
	URL string
}

Ingredients object represents options for Antidote.

Jump to

Keyboard shortcuts

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