Documentation ¶
Index ¶
- Constants
- Variables
- func CopyDir(src, dist string) error
- func CreateCategoryOrders(categories string) map[string]int
- func CreateDescription(htmlStr string) (string, error)
- func CreateHTML(layout, title, body, description, url, cssPath, indexMenu, headerList string) string
- func CreateHTMLFileDir(dir, sourceDir, outputDir string) string
- func CreateHash(text string) string
- func CreateHeaderList(md string) (string, error)
- func CreateIndexMenu(items []IndexItem) string
- func CreateIndexPage(layout, baseURL, header, title, description, cssPath string, ...) (string, error)
- func CreatePage(layout, md, title, url, cssPath, indexMenu, headerList string) (string, error)
- func CreateRssFileTask(pages []*Page, tz, outputDir, baseURL, title, description string) func() error
- func CreateTitle(md string) string
- func CreateURL(dir, name, sourceDir, baseURL string) string
- func Filter[T any](items []T, callbackFn func(item T, index int) (bool, error)) ([]T, error)
- func GetDirAndName(path string) (string, string)
- func GetMarkDownFileNames(fp IFilePath, root string) ([]string, error)
- func GetMd(content string) (string, error)
- func ImageSize(path string) (int, int, error)
- func IsCode(line string) bool
- func IsDirExists(path string) bool
- func IsHeader(line string) bool
- func Keys[K comparable, V any](items map[K]V) []K
- func Map[T any, R any](items []T, callbackFn func(item T, index int) (R, error)) ([]R, error)
- func MapToSlice[V any](m map[int]V) ([]V, error)
- func NewMarkdown() goldmark.Markdown
- type Category
- type FilePath
- type IFilePath
- type IndexItem
- type IndexItemPage
- type IndexItemPagesMap
- type Meta
- type Page
- type PageMeta
- type SortedLimitedArray
Constants ¶
const ( BODY = "__BODY__" HEADER = "__HEADER__" INDEX = "__INDEX__" CSS = "__CSS__" URL = "__URL__" IMAGE_DIR = "images" CSS_FILE_NAME = "app.css" )
const ( DateTime = "2006-01-02 15:04" MAX_RSS_ITEMS = 20 RSS_FILE_NAME = "rss.xml" ITEM_TEMPLATE = `` /* 126-byte string literal not displayed */ RSS_TEMPLATE = `` /* 311-byte string literal not displayed */ )
Variables ¶
var ( TITLE = regexp.MustCompile("__TITLE__") DESCRIPTION = regexp.MustCompile("__DESCRIPTION__") SEPARATOR = regexp.MustCompile(`---(.*)`) )
Functions ¶
func CopyDir ¶
CopyDir copies a directory from src to dist. It supports both Windows and Unix-like operating systems. On Windows, it uses robocopy, and on Unix-like systems, it uses cp. It returns an error with a stack trace
func CreateCategoryOrders ¶
CreateCategoryOrders takes a string of categories separated by commas, trims any trailing comma, and then splits the string into individual categories. It creates and returns a map where each category is a key with its value being the order (index) in which the category appears in the input string. If a category appears more than once, it is only added to the map once, with the index of its first occurrence.
Parameters: - categories: A string of categories separated by commas. For example, "apple,orange,banana,apple".
Returns:
- A map[string]int where keys are unique categories from the input string and values are the indexes at which those categories first appear in the input string.
Note: This function does not account for spaces around category names. For example, "apple, orange" will treat " orange" (with a leading space) as a distinct category from "orange".
func CreateDescription ¶
CreateDescription generates a description from an HTML string. It extracts text nodes and removes newlines and specific characters, then uses the first 300 characters to generate the description.
func CreateHTML ¶
func CreateHTML(layout, title, body, description, url, cssPath, indexMenu, headerList string) string
CreateHTML generates an HTML page using the given parameters. It applies the parameters to the layout template and returns the completed HTML string.
func CreateHTMLFileDir ¶
CreateHTMLFileDir constructs the file path for an HTML file based on the given directory, source directory, and output directory. It calculates the subdirectory path by removing the source directory prefix from the given directory path. This subdirectory path is then appended to the output directory to form the final file path. Parameters: - dir: The directory where the original Markdown file resides. It is expected to be a subdirectory of the source directory. - sourceDir: The root directory of all source Markdown files. - outputDir: The root directory where the resulting HTML files should be saved. Returns: The constructed file path for the HTML file, which combines the output directory and the subdirectory derived from the given directory, excluding the source directory prefix.
func CreateHash ¶
CreateHash generates a hash value from the given text. It replaces specific characters with "_", "-_", and "_-" to create the hash.
func CreateHeaderList ¶
CreateHeaderList generates HTML for a header list from markdown text.
func CreateIndexMenu ¶
CreateIndexMenu generates an HTML navigation menu from a slice of IndexItem.
func CreateIndexPage ¶
func CreateIndexPage(layout, baseURL, header, title, description, cssPath string, indexItems []IndexItem) (string, error)
CreateIndexPage generates the HTML for an index page from index items.
func CreatePage ¶
CreatePage generates the HTML for an individual page using the given parameters.
func CreateRssFileTask ¶
func CreateTitle ¶
CreateTitle generates a title from the markdown text. It uses the first heading (# Title) as the title.
func CreateURL ¶
CreateURL generates a URL from the specified directory and file name. It constructs the URL based on the source directory and base URL obtained from environment variables.
func Filter ¶
Filter applies a callback function to each item in a slice and returns a new slice containing only the items for which the callback returns true. The callback function receives an item and its index as arguments and returns a boolean and an error. If the callback function returns an error, the filtering process stops and the error is returned.
func GetDirAndName ¶
GetDirAndName extracts the directory path and file name (without extension) from a file path.
func GetMarkDownFileNames ¶
GetMarkDownFileNames searches the specified root directory and all of its subdirectories for files with the ".md" extension and returns a slice containing the paths of all markdown files found. Parameters: - root: The root directory from which the search will begin.
func ImageSize ¶
ImageSize takes the path to an image file and returns the dimensions of the image. Supported image formats include JPEG, PNG, GIF, BMP, TIFF, and WEBP, thanks to the standard image package and additional formats provided by the golang.org/x/image package.
Parameters: - path: A string representing the filesystem path to the image file.
Returns: - The width (Dx) and height (Dy) of the image as integers. - An error if the file cannot be opened, or if the image format is not recognized or is corrupt.
func IsDirExists ¶
IsDirExists checks if the directory at the given path exists. It returns true if the directory exists, and false otherwise.
func Keys ¶
func Keys[K comparable, V any](items map[K]V) []K
Keys extracts the keys from a map and returns them as a slice. The order of the keys in the returned slice is not specified and may vary.
func Map ¶
Map applies a callback function to each item in a slice and returns a new slice of the results. The callback function receives an item and its index as arguments and returns a new value and an error. If the callback function returns an error, the mapping process stops and the error is returned.
func MapToSlice ¶
MapToSlice converts a map with integer keys to a slice. It sorts the keys and populates the slice with values in that order.
func NewMarkdown ¶
NewMarkdown initializes a new goldmark.Markdown instance with custom rendering logic. It includes GitHub Flavored Markdown (GFM) extensions and sets the custom renderer with high priority.
Types ¶
type IndexItem ¶
type IndexItem struct { Name string `json:"name,omitempty"` Pages []IndexItemPage `json:"pages,omitempty"` }
func CreateIndexItems ¶
CreateIndexItems generates a slice of IndexItem from a slice of Pages. It organizes pages by header order and creates IndexItem structs containing each header and page titles and URLs.
type IndexItemPage ¶
type IndexItemPagesMap ¶
type IndexItemPagesMap map[int]IndexItemPage
type Meta ¶
type Meta struct { Category Category `json:"header,omitempty"` Order int `json:"order,omitempty"` Date string `json:"date,omitempty"` }
func GetMetaAndMd ¶
GetMetaAndMd extracts metadata and markdown text from the content of a markdown file. The content is split by "---", where the first part is interpreted as JSON format metadata, and the second part as markdown text.
type Page ¶
type Page struct { Meta Meta `json:"meta,omitempty"` Title string `json:"title,omitempty"` URL string `json:"url,omitempty"` }
func CreatePageData ¶
func CreatePageData(markDownFileName, sourceDir, baseURL string, categoryOrders map[string]int) (*Page, error)
CreatePageData generates page data from a markdown file name. It parses the file content to extract metadata, title, and URL, and returns a Page struct containing these.
type SortedLimitedArray ¶
type SortedLimitedArray[T any] struct { Items []T // Items holds the elements of the array. Limit int // Limit specifies the maximum number of elements the array can hold. CompareFn func(a, b T) bool // CompareFn is the function used to compare elements in the array. }
SortedLimitedArray represents a slice that maintains a limited number of elements in a sorted order. The slice is constrained to the specified limit and sorted based on the provided comparison function.
func NewSortedLimitedArray ¶
func NewSortedLimitedArray[T any](items []T, limit int, compareFn func(a, b T) bool) *SortedLimitedArray[T]
NewSortedLimitedArray creates and returns a new SortedLimitedArray with the specified limit and comparison function.
func (*SortedLimitedArray[T]) Push ¶
func (s *SortedLimitedArray[T]) Push(items ...T)
Push adds elements to the array and then sorts and truncates it to ensure it doesn't exceed the specified limit. The elements are added to the array, and then the array is sorted and truncated according to the CompareFn and Limit.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mock_utils is a generated GoMock package.
|
Package mock_utils is a generated GoMock package. |