From b21d0424ad6bf3cec141abe7e1bb624744c12fc6 Mon Sep 17 00:00:00 2001 From: Louie S Date: Wed, 18 Oct 2023 18:08:59 -0400 Subject: Rewrite to base off template; index more terms --- Makefile | 29 ++++++++++++++-- README | 17 ---------- README.md | 33 ++++++++++++++++++ README.template | 17 ++++++++++ src/index.sh | 95 ---------------------------------------------------- src/index_pages.sh | 42 +++++++++++++++++++++++ src/index_terms.sh | 39 +++++++++++++++++++++ src/lib/create_table | 7 ++++ src/lib/get_type | 13 +++++++ src/lib/insert | 8 +++++ 10 files changed, 185 insertions(+), 115 deletions(-) delete mode 100644 README create mode 100644 README.md create mode 100644 README.template delete mode 100755 src/index.sh create mode 100755 src/index_pages.sh create mode 100755 src/index_terms.sh create mode 100644 src/lib/create_table create mode 100644 src/lib/get_type create mode 100644 src/lib/insert diff --git a/Makefile b/Makefile index 4285a82..2d70777 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,29 @@ MANUAL_SRC = tmp/ncurses-* MANUAL_PATH = ncurses-*/doc/html MANUAL_FILE = $(MANUAL_SRC)/doc/html +ERROR_DOCSET_NAME = $(error DOCSET_NAME is unset) +WARNING_MANUAL_URL = $(warning MANUAL_URL is unset) +ERROR_MANUAL_FILE = $(error MANUAL_FILE is unset) +.phony: err warn + +ifndef DOCSET_NAME +err: ; $(ERROR_DOCSET_NAME) +endif + +ifndef MANUAL_FILE +err: ; $(ERROR_MANUAL_FILE) +endif + +ifndef MANUAL_URL +warn: + $(WARNING_MANUAL_URL) + $(MAKE) all +endif + DOCSET = $(INFO_PLIST_FILE) $(INDEX_FILE) +ifdef SRC_ICON +DOCSET += $(ICON_FILE) +endif all: $(DOCSET) @@ -58,9 +80,10 @@ $(DOCUMENTS_DIR): $(RESOURCES_DIR) $(MANUAL_FILE) $(INFO_PLIST_FILE): src/Info.plist $(CONTENTS_DIR) cp src/Info.plist $@ -$(INDEX_FILE): src/index.sh $(DOCUMENTS_DIR) +$(INDEX_FILE): src/index_pages.sh src/index_terms.sh $(DOCUMENTS_DIR) rm -f $@ - src/index.sh $@ $(DOCUMENTS_DIR)/* + src/index_pages.sh $@ $(shell find $(DOCUMENTS_DIR)/ -iname *.html) + src/index_terms.sh $@ $(DOCUMENTS_DIR)/man/ncurses.3x.html #$(ICON_FILE): src/icon.png $(DOCSET_DIR) -# cp src/icon.png $@ +# cp $(SRC_ICON) $@ diff --git a/README b/README deleted file mode 100644 index 69c98be..0000000 --- a/README +++ /dev/null @@ -1,17 +0,0 @@ -Here is a script and a Makefile for generating an ncurses docset for Dash. The script is loosely based on benzado's script for GNU Make https://github.com/benzado/gnu-make-dash-docset. - -- ncurses: https://invisible-island.net/ncurses/ -- Dash: https://kapeli.com/dash - -To generate a docset from the latest edition of ncurses, simply -execute `make` from the same directory as this README file. The latest edition -will be downloaded from www.invisible-island.net and packaged appropriately. - -A specific version can also be downloaded and packaged by running `make VERSION=...`. - -Requirements: - -- any POSIX-compliant shell -- curl -- make -- sqlite3 diff --git a/README.md b/README.md new file mode 100644 index 0000000..774f7de --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Dash Docset Template + +This is a repository providing a template to package a Dash docset from HTML source documentation. Files that need to be manually configured are listed below. Additional fine tuning is also recommended, depending on the quirks of the documentation being packaged. An example docset packaging script for GNU Make using this template can be seen [here](https://github.com/lshprung/gnu-make-dash-docset) + +### `README.template` + +This file will provide a README for the packaging script. Replace ``, ``, and `` with appropriate values. + +### `Makefile` + +This file will build the docset. + +- `DOCSET_NAME` must be set +- `MANUAL_FILE` must be set + - If the script should download documentation from the internet, `MANUAL_URL` must also be set. If not, ensure a `.tgz` archive of the HTML documentation exists at `tmp/MANUAL.tgz` (where MANUAL is the name of the archive) + +### `src/icon.png` + +If you want to associate an icon with the docset, it should be saved to `src/icon.png`. Make sure to uncomment the corresponding line in `Makefile` to include the icon in the docset. + +### `src/index.sh` + +This is the main script that builds the docset index. This script does not require any manual modifications, but you will probably want to make additions/changes to improve the quality of your docset and accomodate any quirks. + +### `src/Info.plist` + +This file contains metadata for the docset. Replace `` with appropriate values. It may be useful to refer to the `Info.plist` file of an existing docset for reference. + +--- + +### Credits + +Created by [lshprung](https://github.com/lshprung), and originally based on [benzado](https://github.com/benzado)'s [gnu-make-dash-docset](https://github.com/benzado/gnu-make-dash-docset). diff --git a/README.template b/README.template new file mode 100644 index 0000000..c4b49dc --- /dev/null +++ b/README.template @@ -0,0 +1,17 @@ +Here is a script and a Makefile for generating a ncurses docset for Dash. The script is based on the dash-docset-generation-template + +- ncurses: https://invisible-island.net/ncurses/ +- Dash: https://kapeli.com/dash +- dash-docset-generation-template: https://github.com/lshprung/dash-docset-generation-template + +To generate a docset from the latest edition of ncurses, simply +execute `make` from the same directory as this README file. The latest edition +will be downloaded from www.invisible-island.net and packaged appropriately. + +Requirements: + +- any POSIX-compliant shell +- curl - https://curl.se/ +- make - https://www.gnu.org/software/make/ +- pup - https://github.com/ericchiang/pup +- sqlite3 - https://www.sqlite.org/index.html diff --git a/src/index.sh b/src/index.sh deleted file mode 100755 index a2a52d0..0000000 --- a/src/index.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env sh - -DB_PATH="$1" -shift - -get_title() { - FILE="$1" - - PATTERN="<[tT][iI][tT][lL][eE]>.*" - - #Find pattern in file - grep -Eo "$PATTERN" "$FILE" | - #Remove tag - sed 's/<[^>]*>//g' | \ - #Remove '(automake)' - sed 's/(Autoconf)//g' | \ - #Remove trailing space - sed 's/[ ]*$//g' | \ - #Remove trailing man categories - sed 's/ [0-9][mx]\?$//g' | \ - #Replace '&' with '&' - sed 's/&/&/g' | \ - # ReplACE '–' with '-' - sed 's/–/-/g' | \ - #Replace '<' with '<' - sed 's/</[^<]*" "$1" | while read -r line; do + insert_term "$line" + done + + shift + done +} + +insert_term() { + LINK="$1" + #NAME="$(echo "$LINK" | pup -p 'a text{}' | sed 's/\"\"//g' | tr -d \\n)" + NAME="$(echo "$LINK" | cut -d ' ' -f 1)" + PAGE_PATH="$(echo "$LINK" | pup -p 'a attr{href}')" + + TYPE=$(get_type "$PAGE_PATH") + if [ -z "$TYPE" ]; then + TYPE="Guide" + fi + + insert "$DB_PATH" "$NAME" "$TYPE" "man/$PAGE_PATH" +} + +create_table "$DB_PATH" +insert_index_terms "$@" diff --git a/src/lib/create_table b/src/lib/create_table new file mode 100644 index 0000000..a783c50 --- /dev/null +++ b/src/lib/create_table @@ -0,0 +1,7 @@ +create_table() { + DB_PATH="$1" + + sqlite3 "$DB_PATH" "CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);" + sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX IF NOT EXISTS anchor ON searchIndex (name, type, path);" +} + diff --git a/src/lib/get_type b/src/lib/get_type new file mode 100644 index 0000000..9f04b53 --- /dev/null +++ b/src/lib/get_type @@ -0,0 +1,13 @@ +get_type() { + FILE="$1" + CATEGORY="$(echo "$FILE" | grep -Eo "\.[0-9].?\.html$")" + + if [ -n "$CATEGORY" ]; then + case "$CATEGORY" in + .1*) echo "Command" ;; + .2*) echo "Service" ;; + .3*) echo "Function" ;; + *) echo "Object" ;; + esac + fi +} diff --git a/src/lib/insert b/src/lib/insert new file mode 100644 index 0000000..31c1b4c --- /dev/null +++ b/src/lib/insert @@ -0,0 +1,8 @@ +insert() { + DB_PATH="$1" + NAME="$2" + TYPE="$3" + PAGE_PATH="$4" + + sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"$PAGE_PATH\");" +} -- cgit