summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-10-18 18:08:59 -0400
committerLouie S <louie@example.com>2023-10-18 18:08:59 -0400
commitb21d0424ad6bf3cec141abe7e1bb624744c12fc6 (patch)
tree82e2fd408075ba531431a183d9b3435b1699d170
parent857c316881e6fede7dfe12daf2eecec539e0179c (diff)
Rewrite to base off template; index more terms
-rw-r--r--Makefile29
-rw-r--r--README17
-rw-r--r--README.md33
-rw-r--r--README.template17
-rwxr-xr-xsrc/index.sh95
-rwxr-xr-xsrc/index_pages.sh42
-rwxr-xr-xsrc/index_terms.sh39
-rw-r--r--src/lib/create_table7
-rw-r--r--src/lib/get_type13
-rw-r--r--src/lib/insert8
10 files changed, 185 insertions, 115 deletions
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 `<NAME>`, `<UPSTREAM LINK>`, and `<UPSTREAM HOST>` 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 `<!-- VALUE -->` 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]>.*</[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 '&amp' with '&'
- sed 's/&amp/&/g' | \
- # ReplACE '&ndash;' with '-'
- sed 's/&ndash;/-/g' | \
- #Replace '&lt;' with '<'
- sed 's/&lt;/</g'
-}
-
-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
-}
-
-insert() {
- NAME="$1"
- TYPE="$2"
- PAGE_PATH="$3"
-
- sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"$PAGE_PATH\");"
-}
-
-skip_check() {
- NAME="$1"
-
- case "$NAME" in
- [A-Z]) return 1 ;;
- "Source Browser") return 1 ;;
- terminal_interface*) return 1 ;;
- esac
-}
-
-# Get title and insert into table for each html file
-main() {
- while [ -n "$1" ]; do
- unset PAGE_NAME
- unset PAGE_TYPE
-
- #echo "FILE: $1"
- # Recurse into subdirectories
- if [ -d "$1" ]; then
- main "$1"/*
- else
- PAGE_NAME="$(get_title "$1")"
- if skip_check "$PAGE_NAME"; then
- if [ -n "$PAGE_NAME" ]; then
- PAGE_TYPE="$(get_type "$1")"
- #get_type "$1"
- if [ -z "$PAGE_TYPE" ]; then
- PAGE_TYPE="Guide"
- fi
- #echo "$PAGE_NAME"
- #echo "$PAGE_TYPE"
- insert "$PAGE_NAME" "$PAGE_TYPE" "$(echo "$1" | sed 's/^ncurses.docset\/Contents\/Resources\/Documents\///')"
- fi
- fi
- fi
-
- shift
- done
-}
-
-# Create table
-sqlite3 "$DB_PATH" "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
-sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);"
-
-main "$@"
diff --git a/src/index_pages.sh b/src/index_pages.sh
new file mode 100755
index 0000000..030bda5
--- /dev/null
+++ b/src/index_pages.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env sh
+
+# shellcheck source=./lib/create_table
+. "$(dirname "$0")"/lib/create_table
+# shellcheck source=./lib/insert
+. "$(dirname "$0")"/lib/insert
+# shellcheck source=./lib/get_type
+. "$(dirname "$0")"/lib/get_type
+
+DB_PATH="$1"
+shift
+
+get_title() {
+ FILE="$1"
+
+ pup -p -f "$FILE" 'title text{}' | \
+ tr -d \\n | \
+ #Remove trailing man categories
+ sed 's/ [0-9][mx]\?$//g' | \
+ sed 's/\"/\"\"/g'
+}
+
+insert_pages() {
+ # Get title and insert into table for each html file
+ while [ -n "$1" ]; do
+ unset PAGE_NAME
+ unset PAGE_TYPE
+
+ PAGE_NAME="$(get_title "$1")"
+ if [ -n "$PAGE_NAME" ]; then
+ PAGE_TYPE="$(get_type "$1")"
+ if [ -z "$PAGE_TYPE" ]; then
+ PAGE_TYPE="Guide"
+ fi
+ insert "$DB_PATH" "$PAGE_NAME" "$PAGE_TYPE" "$(echo "$1" | sed 's/^ncurses.docset\/Contents\/Resources\/Documents\///')"
+ fi
+ shift
+ done
+}
+
+create_table "$DB_PATH"
+insert_pages "$@"
diff --git a/src/index_terms.sh b/src/index_terms.sh
new file mode 100755
index 0000000..a2b39fb
--- /dev/null
+++ b/src/index_terms.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env sh
+
+# shellcheck source=./lib/create_table
+. "$(dirname "$0")"/lib/create_table
+# shellcheck source=./lib/insert
+. "$(dirname "$0")"/lib/insert
+# shellcheck source=./lib/get_type
+. "$(dirname "$0")"/lib/get_type
+
+DB_PATH="$1"
+shift
+
+insert_index_terms() {
+ # Get each term from an index page and insert
+ while [ -n "$1" ]; do
+ grep -Eoi "^[a-zA-Z_ ]{45}<STRONG><A HREF=\"[^\"]*\">[^<]*</A></STRONG>" "$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\");"
+}