compact

package module
v0.0.0-...-da2e56a Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2014 License: MIT Imports: 10 Imported by: 0

README

compact

Merge external js/css/images into a single HTML file.

Why

A beautifuy HTML page contains CSS, images and even javascript. But it's painful to distribute. You have to compress all files, send, uncompress, and then figure out which file to open in your browser.

It's much easier if all these go into a single HTML file.

Features

  • Include external CSS file
  • Include external JS file
  • Turn <img> into data-uri format
  • Turn css background-image into data-uri format
  • Custom ignore function

Command Line Usage

compact http://github.com github.html
compact /path/to/local/file.html result.html

Package Usage

package main

import (
    "github.com/ddliu/go-compact"
    "net/url"
    "fmt"
)

func main() {
    // u, _ := url.Parse("/home/dong/project/example.html")
    u, _ := url.Parse("http://github.com")
    content, err := compact.Convert(u, func(u *url.Url) bool {
        if u.Host == "google.com" {
            return true
        }
    })

    fmt.Println(content)
}

Limit

  • Webfont not supported
  • The convertion is done with the help of regexp, so it might not work for some HTML pages

Changelog

v0.1.0 (2014-02-28)

Initial release

Documentation

Index

Constants

View Source
const (
	U_URL = iota
	U_FILE
	U_DATA
	U_UNKNOWN
)

URL types(local file is also considered as url)

Variables

This section is empty.

Functions

func Convert

func Convert(u *url.URL, ignore func(*url.URL) bool) (string, error)

func ConvertContentImage

func ConvertContentImage(content string, u *url.URL, ignoreImageUrlFunc func(*url.URL) bool) string

Convert images in html into data-uri format

func ConvertCssImage

func ConvertCssImage(content string, u *url.URL, ignoreImageUrlFunc func(*url.URL) bool) string

Convert background images into data-uri format

func ConvertDataURI

func ConvertDataURI(u *url.URL) (string, error)

Convert url into data-uri format

func ConvertExternalCss

func ConvertExternalCss(content string, u *url.URL, ignoreCssUrlFunc func(*url.URL) bool, ignoreImageUrlFunc func(*url.URL) bool) string

Embed external css files

func ConvertExternalJs

func ConvertExternalJs(content string, u *url.URL, ignore func(*url.URL) bool) string

Embed external js files

Types

type Converter

type Converter struct {
	IgnoreFunc             func(*url.URL) bool
	IgnoreContentImageFunc func(*url.URL) bool
	IgnoreCssFunc          func(*url.URL) bool
	IgnoreCssImageFunc     func(*url.URL) bool
	IgnoreJsFunc           func(*url.URL) bool
}

func (*Converter) Convert

func (this *Converter) Convert(u *url.URL) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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