html_breadcrumb_insert

package module
Version: v0.0.0-...-0b7cbec Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 12 Imported by: 0

README

HTML Breadcrumbs Insert Tool

This tool inserts breadcrumbs into HTML files directly.

Install

This tool is implemented in Go. So you need to install Go compiler to run.

Install with go get
$ go get -u gitlab.com/tjkendev/html-breadcrumbs-insert/cmd/bcinsert
Command install from source code
$ make install

Usage

Basic usage: Insert breadcrumbs in target directory recursively

$ bcinsert -i <target-directory> -c <breadcrumb-config (YAML file)>

If you want to remove breadcrumbs after insertion, you can remove them with -r option.

$ bcinsert -i <target-directory> -c <breadcrumb-config (YAML file)> -r
Example

Suppose that directory structure of current directory is like below

.
├── breadcrumb.yml
└── public
    ├── A1
    │   └── A2
    │       └── test.html
    ├── C1
    │   ├── C2
    │   │   └── test.html
    │   └── index.html
    ├── index.html
    └── sample.html

and write a config file (breadcrumb.yml) like below.

# "TargetSelector": jQuery selector to append breadcrumbs in HTML files (In this example, breadcrumbs is inserted into elmenets with "header" id attribute)
TargetSelector: "#header"
# "DefaultIndex": default index page in parent directories
DefaultIndex: "index.html"
# "HTMLExtension": file extension of HTML files
HTMLExtension: "html"
# "TagName": a tag name of breadcrumb's root element
TagName: "div"
# "BreadcrumbRootID": an id attribute's value contained in breadcrumb's root element
BreadcrumbRootID: "breadcrumb"
# "BreadcrumbLinkClass": class names contained in 'a' tags which is linked to a page in breadcrumbs
BreadcrumbLinkClass: "breadcrumb-link"
# "BreadcrumbNoLinkClass": class names contained in 'span' tags which is not linked to a page in breadcrumbs
BreadcrumbNoLinkClass: "breadcrumb-text"
# "Separator": breadcrumbs' hierarchy separator
Separator: '>'
# "BreadcrumbStrcut": directories information to insert breadcrumbs
BreadcrumbStruct:
  index: "home"
  A1:
    # "__index": hidden index name (no link in breadcrumbs)
    __index: "A" 
    A2:
      test: "test1"
  sample: "sample"
  C1:
    index: "C"
    C2:
      test: "test2"

And, run this tool to insert breadcrumbs.

bcinsert -i ./public -c ./breadcrumb.yml

In ./A1/A2/test.html, for instance, HTML text like below will be inserted into elements with header id attribute,

<div id="breadcrumb"><a href="../../index.html" class="breadcrumb-link">home</a> &gt; <span class="breadcrumb-text">A</span> &gt; <a href="./test.html" class="breadcrumb-link">test1</a></div></div>

and this breadcrumb will be viewed in web browsers like below (home and test1 is linked to the corresponding page):

home > A > test1

Documentation

Index

Constants

View Source
const (
	// DefaultIndexPage is default index filename of parent directories.
	DefaultIndexPage = "index.html"

	// DefaultHomeName is default breadcrumb name of root directory.
	DefaultHomeName = "home"
	// DefaultIndexName is default breadcrumb name of index page.
	DefaultIndexName = "index"
	// DefaultHTMLExtension is default extension of HTML files.
	DefaultHTMLExtension = "html"

	// DefaultTargetSelector is default selector for specifying where you want to insert breadcrumbs in html.
	DefaultTargetSelector = "#header"
	// DefaultTagName is a default tag name of breadcrumb's root element in html.
	DefaultTagName = "div"
	// DefaultBreadcrumbID is default id attribute's value contained in breadcrumb's root element in html. (default: id="breadcrumb")
	DefaultBreadcrumbID = "breadcrumb"
	// DefaultBreadcrumbLinkClass is default class names of breadcrumb which is linked to some page.
	DefaultBreadcrumbLinkClass = "breadcrumb-link"
	// DefaultBreadcrumbNoLinkClass is default class names of breadcrumb which is not linked to any page.
	DefaultBreadcrumbNoLinkClass = "breadcrumb-text"
	// DefaultSeparator is default hierarchy separator of breadcrumbs. (default: ">")
	DefaultSeparator = "&gt;"
)

Variables

This section is empty.

Functions

func InsertBreadcrumbs

func InsertBreadcrumbs(config *BreadcrumbConfig, rootDirNode *DirNode) error

InsertBreadcrumbs inserts breadcrumbs into HTML files with specified config and directories.

Types

type BreadcrumbConfig struct {
	// BreadcrumbStruct is a tree structure which have infomation to insert breadcrumbs.
	BreadcrumbStruct BreadcrumbNode `yaml:"BreadcrumbStruct"`

	// OnlyRemove is an option. If this value is true, this tool only remove breadcrumbs already inserted.
	OnlyRemove bool `yaml:"-"`

	// DefaultIndex is a name of default index pages. (default "index.html")
	DefaultIndex string `yaml:"DefaultIndex"`

	// HTMLExtension is a file extension of HTML files.
	HTMLExtension string `yaml:"HTMLExtension"`

	// TagName is a tag name of breadcrumb's root element.
	TagName string `yaml:"TagName"`

	// BreadcrumbRootID is an id attribute's value contained in breadcrumb's root element.
	BreadcrumbRootID string `yaml:"BreadcrumbRootID"`

	// BreadcrumbLinkClass is class names contained in 'a' tags which is linked to a page in breadcrumbs.
	BreadcrumbLinkClass string `yaml:"BreadcrumbLinkClass"`

	// BreadcrumbNoLinkClass is class names contained in 'span' tags which is not linked to a page in breadcrumbs.
	BreadcrumbNoLinkClass string `yaml:"BreadcrumbNoLinkClass"`

	// Separator is a breadcrumb hierarchy separator.
	Separator string `yaml:"Separator"`

	// TargetSelector is a target selector for inserting breadcrumb.
	TargetSelector string `yaml:"TargetSelector"`
}

BreadcrumbConfig is configuration struct for this tool.

func LoadBreadcrumbConfig

func LoadBreadcrumbConfig(yamlFileName string) (*BreadcrumbConfig, error)

LoadBreadcrumbConfig loads a breadcrumb config from a specified YAML file.

type BreadcrumbNode struct {
	IndexName   string
	HiddenIndex bool
	NameMap     map[string]string
	DirMap      map[string]*BreadcrumbNode
}

BreadcrumbNode is node struct for representing breadcrumb info.

func (n *BreadcrumbNode) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshals a YAML Data to load a breadcrumb config.

type DirNode

type DirNode struct {
	PathName string
	NameMap  map[string]struct{}
	DirMap   map[string]*DirNode
}

DirNode is node struct for representing directory structure

func GetHTMLFiles

func GetHTMLFiles(directory, extension string) (*DirNode, error)

GetHTMLFiles gets all HTML files in a specified directory recursively

type EntireConfig

type EntireConfig struct {
	OnlyRemove            bool
	IndexPage             string
	Extension             string
	SelectorName          string
	BreadcrumbID          string
	BreadcrumbLinkClass   string
	BreadcrumbNoLinkClass string
	TagName               string
	Separator             string
}

EntireConfig is an injection config struct which is referred when injecting breadcrumbs

type PageInfo

type PageInfo struct {
	Level    int
	Name     string
	FileName string
	NoLink   bool
}

PageInfo is a page info of each page showed in breadcrumbs.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL