mirror of
https://github.com/Retropex/raspiblitz.git
synced 2025-05-12 19:20:48 +02:00
Toc - Table of Contents (#2943)
This commit is contained in:
parent
c46fe4b499
commit
a92f856709
@ -1,6 +1,9 @@
|
||||
<!-- omit in toc -->
|
||||
# C-lightning on the RaspiBlitz FAQ
|
||||
|
||||
---
|
||||
Table of Contents
|
||||
---
|
||||
- [Common questions about the different Lightning Network implementations](#common-questions-about-the-different-lightning-network-implementations)
|
||||
- [Can LND and C-lightning nodes open channels to each other and route payments?](#can-lnd-and-c-lightning-nodes-open-channels-to-each-other-and-route-payments)
|
||||
- [Can I run LND and C-lightning connected to the same node?](#can-i-run-lnd-and-c-lightning-connected-to-the-same-node)
|
||||
@ -43,7 +46,6 @@
|
||||
- [Experimental update to the latest master](#experimental-update-to-the-latest-master)
|
||||
- [sqlite3 queries](#sqlite3-queries)
|
||||
- [Script file help list](#script-file-help-list)
|
||||
|
||||
---
|
||||
## Common questions about the different Lightning Network implementations
|
||||
|
||||
|
57
FAQ.md
57
FAQ.md
@ -1,31 +1,10 @@
|
||||
<!-- omit in toc -->
|
||||
# FAQ - Frequently Asked Questions
|
||||
|
||||
---
|
||||
Table of Contents
|
||||
---
|
||||
- [Upgrade](#upgrade)
|
||||
- [Is using the prepared SD card image secure?](#is-using-the-prepared-sd-card-image-secure)
|
||||
- [How to verify the SD card image after download?](#how-to-verify-the-sd-card-image-after-download)
|
||||
- [What changed on every upgrade?](#what-changed-on-every-upgrade)
|
||||
- [How do I upgrade my RaspiBlitz?](#how-do-i-upgrade-my-raspiblitz)
|
||||
- [Why do I need to re-burn my SD card for an update?](#why-do-i-need-to-re-burn-my-sd-card-for-an-update)
|
||||
- [How can I update LND or bitcoind even before the next RaspiBlitz update?](#how-can-i-update-lnd-or-bitcoind-even-before-the-next-raspiblitz-update)
|
||||
|
||||
- [SSH](#ssh)
|
||||
- [What to do when on SSH I see "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"](#what-to-do-when-on-ssh-i-see-warning-remote-host-identification-has-changed)
|
||||
- [How do I unplug/shutdown safely without SSH](#how-do-i-unplugshutdown-safely-without-ssh)
|
||||
- [I cannot connect via SSH to my RaspiBlitz. What do I do?](#i-cannot-connect-via-ssh-to-my-raspiblitz-what-do-i-do)
|
||||
- [How to SSH over Tor?](#how-to-ssh-over-tor)
|
||||
- [How to setup port-forwarding with a SSH tunnel?](#how-to-setup-port-forwarding-with-a-ssh-tunnel)
|
||||
- [How do I setup just a port-forwarding user on my public server?](#how-do-i-setup-just-a-port-forwarding-user-on-my-public-server)
|
||||
- [How can I repair my SSH login?](#how-can-i-repair-my-ssh-login)
|
||||
|
||||
- [Display](#display)
|
||||
- [Can I flip the screen?](#can-i-flip-the-screen)
|
||||
- [How to fix my upside down LCD after update?](#how-to-fix-my-upside-down-lcd-after-update)
|
||||
- [Can I run the RaspiBlitz without a display/LCD?](#can-i-run-the-raspiblitz-without-a-displaylcd)
|
||||
- [How do I find the IP address when running without a display?](#how-do-i-find-the-ip-address-when-running-without-a-display)
|
||||
|
||||
- [Upgrade](#upgrade)
|
||||
- [Is using the prepared SD card image secure?](#is-using-the-prepared-sd-card-image-secure)
|
||||
- [How to verify the SD card image after download?](#how-to-verify-the-sd-card-image-after-download)
|
||||
- [What changed on every upgrade?](#what-changed-on-every-upgrade)
|
||||
- [How do I upgrade my RaspiBlitz?](#how-do-i-upgrade-my-raspiblitz)
|
||||
@ -34,7 +13,7 @@
|
||||
- [SSH](#ssh)
|
||||
- [What to do when on SSH I see "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"](#what-to-do-when-on-ssh-i-see-warning-remote-host-identification-has-changed)
|
||||
- [How do I unplug/shutdown safely without SSH](#how-do-i-unplugshutdown-safely-without-ssh)
|
||||
- [I cannot connect via SSH to my RaspiBlitz. What do I do?](#i-cannot-connect-via-ssh-to-my-raspiblitz-what-do-i-do)
|
||||
- [I cannot connect via SSH to my RaspiBlitz. What do I do?](#i-cannot-connect-via-ssh-to-my-raspiblitz.-what-do-i-do)
|
||||
- [How to SSH over Tor?](#how-to-ssh-over-tor)
|
||||
- [How to setup port-forwarding with a SSH tunnel?](#how-to-setup-port-forwarding-with-a-ssh-tunnel)
|
||||
- [How do I setup just a port-forwarding user on my public server?](#how-do-i-setup-just-a-port-forwarding-user-on-my-public-server)
|
||||
@ -44,11 +23,11 @@
|
||||
- [Can I run the RaspiBlitz without a display/LCD?](#can-i-run-the-raspiblitz-without-a-displaylcd)
|
||||
- [How do I find the IP address when running without a display?](#how-do-i-find-the-ip-address-when-running-without-a-display)
|
||||
- [Debug](#debug)
|
||||
- [I have the full blockchain on another storage. How do I copy it to the RaspiBlitz?](#i-have-the-full-blockchain-on-another-storage-how-do-i-copy-it-to-the-raspiblitz)
|
||||
- [I have the full blockchain on another storage. How do I copy it to the RaspiBlitz?](#i-have-the-full-blockchain-on-another-storage.-how-do-i-copy-it-to-the-raspiblitz)
|
||||
- [How do I generate a Debug Report?](#how-do-i-generate-a-debug-report)
|
||||
- [Why is my "final sync" taking so long?](#why-is-my-final-sync-taking-so-long)
|
||||
- [How do I backup my Lightning Node?](#how-do-i-backup-my-lightning-node)
|
||||
- [1) Securing your On-Chain- and Channel-Funds during Operation](#1-securing-your-on-chain--and-channel-funds-during-operation)
|
||||
- [1) Securing your On-Chain- and Channel-Funds during Operation](#and-channel-funds-during-operation)
|
||||
- [2) Making a complete LND data backup](#2-making-a-complete-lnd-data-backup)
|
||||
- [How can I recover my coins from a failing RaspiBlitz?](#how-can-i-recover-my-coins-from-a-failing-raspiblitz)
|
||||
- [1) Recover LND data](#1-recover-lnd-data)
|
||||
@ -66,7 +45,7 @@
|
||||
- [Why is my node address on the display yellow (not green)?](#why-is-my-node-address-on-the-display-yellow-not-green)
|
||||
- [How do I fix a displayed Error in my Config?](#how-do-i-fix-a-displayed-error-in-my-config)
|
||||
- [Can I run the RaspiBlitz as Backend for BTCPayServer?](#can-i-run-the-raspiblitz-as-backend-for-btcpayserver)
|
||||
- [I don't have a LAN port on my Laptop - how do I connect to my RaspiBlitz?](#i-dont-have-a-lan-port-on-my-laptop---how-do-i-connect-to-my-raspiblitz)
|
||||
- [I don't have a LAN port on my Laptop - how do I connect to my RaspiBlitz?](#how-do-i-connect-to-my-raspiblitz)
|
||||
- [Is it possible to connect the Blitz over Wifi instead of using a LAN cable?](#is-it-possible-to-connect-the-blitz-over-wifi-instead-of-using-a-lan-cable)
|
||||
- [Can I directly connect the RaspiBlitz to my laptop?](#can-i-directly-connect-the-raspiblitz-to-my-laptop)
|
||||
- [How to attach the RaspberryPi to the HDD?](#how-to-attach-the-raspberrypi-to-the-hdd)
|
||||
@ -74,10 +53,9 @@
|
||||
- [Are those "Under-Voltage detected" warnings a problem?](#are-those-under-voltage-detected-warnings-a-problem)
|
||||
- [How do I return to the menu after exiting to the command line](#how-do-i-return-to-the-menu-after-exiting-to-the-command-line)
|
||||
- [How do I setup fresh/clean/reset and without going into recovery mode?](#how-do-i-setup-freshcleanreset-and-without-going-into-recovery-mode)
|
||||
- [My blockchain data is corrupted - what can I do?](#my-blockchain-data-is-corrupted---what-can-i-do)
|
||||
- [I have two RaspiBlitz in my network - can they both be public?](#i-have-two-raspiblitz-in-my-network---can-they-both-be-public)
|
||||
- [My blockchain data is corrupted - what can I do?](#what-can-i-do)
|
||||
- [I have two RaspiBlitz in my network - can they both be public?](#can-they-both-be-public)
|
||||
- [How can I enforce UASP mode for my SSD controller?](#how-can-i-enforce-uasp-mode-for-my-ssd-controller)
|
||||
|
||||
- [Development](#development)
|
||||
- [What is the process of creating a new SD card image release?](#what-is-the-process-of-creating-a-new-sd-card-image-release)
|
||||
- [How can I customize my RaspiBlitz or add other software?](#how-can-i-customize-my-raspiblitz-or-add-other-software)
|
||||
@ -90,15 +68,14 @@
|
||||
- [How can I sync a branch of my forked GitHub with my local RaspiBlitz?](#how-can-i-sync-a-branch-of-my-forked-github-with-my-local-raspiblitz)
|
||||
- [How contribute a feature/change from my forked branch back to the RaspiBlitz repo?](#how-contribute-a-featurechange-from-my-forked-branch-back-to-the-raspiblitz-repo)
|
||||
- [How can I help testing a Pull Request?](#how-can-i-help-testing-a-pull-request)
|
||||
|
||||
- [Extras](#extras)
|
||||
- [How do I connect a UPS to the RaspiBlitz?](#how-do-i-connect-a-ups-to-the-raspiblitz)
|
||||
- [Can I run my RaspiBlitz on Solar Energy?](#can-i-run-my-raspiblitz-on-solar-energy)
|
||||
- [How to use the Let's Encrypt client](#how-to-use-the-lets-encrypt-client)
|
||||
- [Let's Encrypt - HTTP-01](#lets-encrypt---http-01)
|
||||
- [Let's Encrypt - DNS-01](#lets-encrypt---dns-01)
|
||||
- [Let's Encrypt - eMail Address](#lets-encrypt---email-address)
|
||||
- [Let's Encrypt - Installation details](#lets-encrypt---installation-details)
|
||||
- [Let's Encrypt - HTTP-01](#http-01)
|
||||
- [Let's Encrypt - DNS-01](#dns-01)
|
||||
- [Let's Encrypt - eMail Address](#email-address)
|
||||
- [Let's Encrypt - Installation details](#installation-details)
|
||||
- [What is this mnemonic seed word list?](#what-is-this-mnemonic-seed-word-list)
|
||||
- [How do I set up VNC?](#how-do-i-set-up-vnc)
|
||||
- [Why use BTRFS on RaspiBlitz?](#why-use-btrfs-on-raspiblitz)
|
||||
@ -363,14 +340,6 @@ If your RaspiBlitz is not working correctly and you like to get help from the co
|
||||
|
||||
*PLEASE NOTICE: It's possible that these logs can contain private information (like IPs, node IDs, ...) - just share publicly what you feel OK with.*
|
||||
|
||||
### Can I run my RaspiBlitz on Solar Energy?
|
||||
|
||||
Yes - take a look at the project of [Chimezie Chuta](https://twitter.com/mezie16/status/1264513274080636928?s=20)
|
||||
|
||||

|
||||
|
||||
More details in his book ["A-Z of Building your own Full Bitcoin Lightning Node: A hand Book for Enthusiasts"](https://blockspace.shop/products/a-z-of-building-your-own-full-bitcoin-lightning-node-a-hand-book-for-enthusiasts)
|
||||
|
||||
### Why is my "final sync" taking so long?
|
||||
|
||||
First of all if you see a final sync over 90% and you can see from time to time small increase - you should be OK ... this can take a looong time to catch up with the network. Only in the case that you actively choose the `SYNC` option in the `Getting the Blockchain` is a final sync under 90% OK. If you did a torrent or a copy from another computer and you are seeing under 90% something went wrong, and the setup process is ignoring your prepared Blockchain and doing a full sync - which can almost take forever on a raspberryPi.
|
||||
|
122
README.md
122
README.md
@ -12,6 +12,128 @@ RaspiBlitz is mainly targeted for learning how to run your own node decentralize
|
||||
Discover & develop the growing ecosystem of the Lightning Network by becoming a full part of it.
|
||||
Build it as part of a [workshop](WORKSHOP.md) or as a weekend project yourself.
|
||||
|
||||
---
|
||||
Table of Contents
|
||||
---
|
||||
- [Feature Overview](#feature-overview)
|
||||
- [DeepDive Video (July 2020)](#deepdive-video-july-2020)
|
||||
- [Time Estimate to Set Up a RaspiBlitz](#time-estimate-to-set-up-a-raspiblitz)
|
||||
- [Hardware Needed](#hardware-needed)
|
||||
- [Buy a ready-2-go RaspiBlitz (Germany, EU and International)](#buy-a-ready-2-go-raspiblitz-germany-eu-and-international)
|
||||
- [Amazon Shopping List (buy parts & build it yourself)](#amazon-shopping-list-buy-parts--build-it-yourself)
|
||||
- [Assemble your RaspiBlitz](#assemble-your-raspiblitz)
|
||||
- [Downloading the Software](#downloading-the-software)
|
||||
- [Write the SD-Card image to your SD Card](#write-the-sd-card-image-to-your-sd-card)
|
||||
- [Boot your RaspiBlitz](#boot-your-raspiblitz)
|
||||
- [Support](#support)
|
||||
- [Documentation](#documentation)
|
||||
- [Groups](#groups)
|
||||
- [Setup Process (Detailed Documentation)](#setup-process-detailed-documentation)
|
||||
- [Basic Setup](#basic-setup)
|
||||
- [LNDRESCUE LND tar.gz-Backupfile (BEST)](#lndrescue-lnd-tar.gz-backupfile-best)
|
||||
- [SEED+SCB Words Seed & channel.backup file (OK)](#seedscb-words-seed--channel.backup-file-ok)
|
||||
- [ONLY SEED Only Seed Word List (Fallback)](#only-seed-only-seed-word-list-fallback)
|
||||
- [Final Setup](#final-setup)
|
||||
- [1. SYNC - Self validate all Blocks](#self-validate-all-blocks)
|
||||
- [2. COPY - Copy from Laptop or another RaspiBlitz over Local Network](#copy-from-laptop-or-another-raspiblitz-over-local-network)
|
||||
- [Main Menu](#main-menu)
|
||||
- [Feature Documentation](#feature-documentation)
|
||||
- [INFO: Raspiblitz Status Screen](#info-raspiblitz-status-screen)
|
||||
- [LIGHTNING (Basic Node Management)](#lightning-basic-node-management)
|
||||
- [FUNDING: Fund your on-chain Wallet](#funding-fund-your-on-chain-wallet)
|
||||
- [CONNECT: Connect to a Peer](#connect-connect-to-a-peer)
|
||||
- [CHANNEL: Open a Channel with Peer](#channel-open-a-channel-with-peer)
|
||||
- [SEND: Pay an Invoice/PaymentRequest](#send-pay-an-invoicepaymentrequest)
|
||||
- [RECEIVE: Create Invoice/PaymentRequest](#receive-create-invoicepaymentrequest)
|
||||
- [NAME: Change name of your Node](#name-change-name-of-your-node)
|
||||
- [CLOSE ALL: Closing all open Channels](#close-all-closing-all-open-channels)
|
||||
- [CASHOUT: Remove Funds from on-chain Wallet](#cashout-remove-funds-from-on-chain-wallet)
|
||||
- [SETTINGS: Basic Settings of RaspiBlitz](#settings-basic-settings-of-raspiblitz)
|
||||
- [Touchscreen (experimental)](#touchscreen-experimental)
|
||||
- [LCD Rotate](#lcd-rotate)
|
||||
- [Run behind Tor](#run-behind-tor)
|
||||
- [Parallel Testnet/Signet](#parallel-testnetsignet)
|
||||
- [ZeroTier](#zerotier)
|
||||
- [LND LIGHTNING LABS NODE](#lnd-lightning-labs-node)
|
||||
- [LND Channel Autopilot](#lnd-channel-autopilot)
|
||||
- [LND Accept Keysend](#lnd-accept-keysend)
|
||||
- [LND Circuitbreaker (Firewall for LND)](#lnd-circuitbreaker-firewall-for-lnd)
|
||||
- [LND Auto-Unlock](#lnd-auto-unlock)
|
||||
- [LND StaticChannelBackup on Nextcloud](#lnd-staticchannelbackup-on-nextcloud)
|
||||
- [StaticChannelBackup on USB Drive](#staticchannelbackup-on-usb-drive)
|
||||
- [StaticChannelBackup per SCP/SSH to other server](#staticchannelbackup-per-scpssh-to-other-server)
|
||||
- [C-LIGHTNING NODE](#c-lightning-node)
|
||||
- [CL CLBOSS Automatic Node Manager](#cl-clboss-automatic-node-manager)
|
||||
- [CL Wallet Encryption](#cl-wallet-encryption)
|
||||
- [SERVICES: Activate/Deactivate Services](#services-activatedeactivate-services)
|
||||
- [Electrum Rust Server](#electrum-rust-server)
|
||||
- [BTCPayServer](#btcpayserver)
|
||||
- [BTC-RPC-Explorer](#btc-rpc-explorer)
|
||||
- [Specter Desktop](#specter-desktop)
|
||||
- [Mempool Space](#mempool-space)
|
||||
- [JoinMarket](#joinmarket)
|
||||
- [Download Bitcoin Whitepaper](#download-bitcoin-whitepaper)
|
||||
- [RTL Webinterface](#rtl-webinterface)
|
||||
- [ThunderHub](#thunderhub)
|
||||
- [Lightning Terminal (LIT) with loop, pool & faraday](#lightning-terminal-lit-with-loop-pool--faraday)
|
||||
- [LNbits](#lnbits)
|
||||
- [Balance of Satoshi](#balance-of-satoshi)
|
||||
- [PyBlock](#pyblock)
|
||||
- [Channel Tools (chantools)](#channel-tools-chantools)
|
||||
- [Sphinx Relay Server](#sphinx-relay-server)
|
||||
- [C-Lightning RTL Webinterface](#c-lightning-rtl-webinterface)
|
||||
- [C-Lightning Sparko Webwallet](#c-lightning-sparko-webwallet)
|
||||
- [C-Lightning Spark Webwallet](#c-lightning-spark-webwallet)
|
||||
- [SYSTEM: Monitoring & Configuration](#system-monitoring--configuration)
|
||||
- [CONNECT: Connect Apps & Credentials](#connect-connect-apps--credentials)
|
||||
- [MOBILE: Mobile Wallet Apps (Smartphone)](#mobile-mobile-wallet-apps-smartphone)
|
||||
- [Electrum Rust Server](#electrum-rust-server-1)
|
||||
- [BTCPAY: Get the connection string for the BTCPay Server](#btcpay-get-the-connection-string-for-the-btcpay-server)
|
||||
- [bitcoinRPC](#bitcoinrpc)
|
||||
- [BISQ: Use your node with BISQ](#bisq-use-your-node-with-bisq)
|
||||
- [EXPORT: Macaroons and TLS.cert](#export-macaroons-and-tls.cert)
|
||||
- [SSH Download](#ssh-download)
|
||||
- [Browser download](#browser-download)
|
||||
- [Hex-String](#hex-string)
|
||||
- [SUBSCRIBE: Subscription Services](#subscribe-subscription-services)
|
||||
- [IP2TOR (paid)](#ip2tor-paid)
|
||||
- [HTTPS with LetsEncrypt (free)](#https-with-letsencrypt-free)
|
||||
- [PASSWORD: Change Passwords](#password-change-passwords)
|
||||
- [REPAIR: Options to test, repair and reset your RaspiBlitz](#repair-options-to-test-repair-and-reset-your-raspiblitz)
|
||||
- [SOFTWARE: Run Software Tests (DebugReport)](#software-run-software-tests-debugreport)
|
||||
- [BACKUP-LND: Backup your LND data (Rescue-File)](#backup-lnd-backup-your-lnd-data-rescue-file)
|
||||
- [RESET-LND: Delete LND & start a node/wallet](#reset-lnd-delete-lnd--start-a-nodewallet)
|
||||
- [REPAIR-CL: Repair/Backup C-Lightning](#repair-cl-repairbackup-c-lightning)
|
||||
- [MIGRATION: Migrate Blitz Data to new Hardware](#migration-migrate-blitz-data-to-new-hardware)
|
||||
- [COPY-SOURCE: Offer your Blockchain to another RaspiBlitz for Setup](#copy-source-offer-your-blockchain-to-another-raspiblitz-for-setup)
|
||||
- [RESET-CHAIN: Delete Blockchain and Re-Download](#reset-chain-delete-blockchain-and-re-download)
|
||||
- [RESET-HDD: Delete HDD data but keep blockchain](#reset-hdd-delete-hdd-data-but-keep-blockchain)
|
||||
- [RESET-ALL: Delete HDD completely & start fresh](#reset-all-delete-hdd-completely--start-fresh)
|
||||
- [DELETE-ELEC: Delete Electrum Index](#delete-elec-delete-electrum-index)
|
||||
- [DELETE-INDEX: Delete Bitcoin TX-Index](#delete-index-delete-bitcoin-tx-index)
|
||||
- [UPDATE: Check/Prepare RaspiBlitz Update](#update-checkprepare-raspiblitz-update)
|
||||
- [RELEASE: Update RaspiBlitz to a new Version](#release-update-raspiblitz-to-a-new-version)
|
||||
- [PATCH: Patch RaspiBlitz code](#patch-patch-raspiblitz-code)
|
||||
- [LND: Interim LND Update](#lnd-interim-lnd-update)
|
||||
- [BITCOIN: Interim Bitcoin Update](#bitcoin-interim-bitcoin-update)
|
||||
- [REBOOT: Reboot RaspiBlitz](#reboot-reboot-raspiblitz)
|
||||
- [OFF: PowerOff RaspiBlitz](#off-poweroff-raspiblitz)
|
||||
- [EXIT: Console Terminal](#exit-console-terminal)
|
||||
- [Import a Migration File](#import-a-migration-file)
|
||||
- [Make a RaspiBlitz out of your Umbrel or MyNode](#make-a-raspiblitz-out-of-your-umbrel-or-mynode)
|
||||
- [Interface / APIs](#interface--apis)
|
||||
- [Bitcoin](#bitcoin)
|
||||
- [LND-Lightning](#lnd-lightning)
|
||||
- [Backup for On-Chain- & Channel-Funds](#-channel-funds)
|
||||
- [A) Nextcloud](#a-nextcloud)
|
||||
- [B) SCP Backup Target](#b-scp-backup-target)
|
||||
- [C) Local Backup Target (USB Thumbdrive)](#c-local-backup-target-usb-thumbdrive)
|
||||
- [Updating RaspiBlitz to new Version](#updating-raspiblitz-to-new-version)
|
||||
- [Build the SD Card Image](#build-the-sd-card-image)
|
||||
- [FAQ](#faq)
|
||||
- [Community Development](#community-development)
|
||||
---
|
||||
|
||||
## Feature Overview
|
||||
|
||||
There are further Services that can be switched on:
|
||||
|
70
toc.sh
Executable file
70
toc.sh
Executable file
@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
## Updated version maintained on https://github.com/nyxnor/scripts/blob/master/toc.sh
|
||||
|
||||
## Produces Table of Contents (ToC) for simple markdown files
|
||||
## Requirement: header is set by hashtag '#'
|
||||
## $1 = FILE.md
|
||||
|
||||
red="\033[31m"
|
||||
#nocolor="\033[0m"
|
||||
|
||||
error_msg(){ printf %s"${red}ERROR: ${1}\n" >&2; exit 1; }
|
||||
|
||||
test -f "${1}" || error_msg "file '${1}' doesn't exist"
|
||||
|
||||
trap 'rm -f toc.tmp' EXIT INT
|
||||
|
||||
line_count=0
|
||||
while IFS="$(printf '\n')" read -r line; do
|
||||
line_count=$((line_count+1))
|
||||
## extract code blocks
|
||||
code="${code:-0}"
|
||||
[ "${code}" -eq 0 ] && printf '%s\n' "${line_count}:${line}" | grep "^${line_count}:.*# "
|
||||
case "${line}" in
|
||||
*\`\`\`*)
|
||||
case "${code}" in
|
||||
1) code=0;;
|
||||
0|*) code=1;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done < "${1}" > toc.tmp
|
||||
|
||||
|
||||
while IFS="$(printf '\n')" read -r line; do
|
||||
## get line number
|
||||
line_number="$(printf '%s\n' "${line}" | cut -d ":" -f1)"
|
||||
## remove hashtag from line to be compared later if it is repeated
|
||||
line_clean="$(printf '%s\n' "${line}" | sed "s/.*\# //")"
|
||||
## save header to cache to check later if it was already printed
|
||||
# shellcheck disable=SC2030
|
||||
line_cache="$(printf '%s\n%s\n' "${line_cache}" "${line}")"
|
||||
## check if header was already printed before and if positive, save all repeated headers
|
||||
## if positive, insert link index
|
||||
line_repeated="$(printf '%s\n' "${line_cache}" | grep -c -- ".*# ${line_clean}$")"
|
||||
line_repeated_index=""
|
||||
## first line does not have '-n', just the first repeated line (second occurence), starting with '-1'. So we consider the occurrence-1.
|
||||
[ "${line_repeated}" -ge 2 ] && line_repeated_index="-$((line_repeated-1))"
|
||||
## if it is the second time line has repeated, save first and second occurrence
|
||||
if [ "${line_repeated}" -eq 2 ]; then
|
||||
line_first_occurrence="$(printf '%s\n' "${line_cache}" | grep -- ".*# ${line_clean}$" | head -n 1)"
|
||||
line_repeated_cache="$(printf '%s\n%s\n' "${line_first_occurrence}" "${line}")"
|
||||
## if it is the third or greater time line has repeated, save lines from before (1st and 2nd occurrence) plus add current lines
|
||||
elif [ "${line_repeated}" -gt 2 ]; then
|
||||
line_repeated_cache="$(printf '%s\n%s\n' "${line_repeated_cache}" "${line}")"
|
||||
fi
|
||||
## clean header that have link reference
|
||||
line_md="$(printf '%s\n' "${line}" | sed "s/${line_number}://;s|](.*||;s|\[||;s/\]//g")"
|
||||
## set header indentation
|
||||
line_md="$(printf '%s\n' "${line_md}" | sed "s|######| -|;s|#####| -|;s|####| -|;s|###| -|;s|##| -|;s|#|-|")"
|
||||
## set link content
|
||||
line_content="$(printf '%s\n' "${line_md}" | sed "s/.*- /#/;s| |-|g;s|'||g;s|]||g;s/|/-/g" | tr "[:upper:]" "[:lower:]" | tr -cd "[:alnum:]-._")"
|
||||
## set link reference
|
||||
line_md="$(printf '%s\n' "${line_md}" | sed "s|- |- [|;s|$|](#${line_content}${line_repeated_index})|")"
|
||||
## print header
|
||||
printf '%s\n' "${line_md}"
|
||||
done < toc.tmp
|
||||
|
||||
[ -n "${line_repeated_cache}" ] &&
|
||||
printf %s"\n\nWARN: Some headers are repeated, the hiperlinks are correctly indexed. If you think this is an error, review these lines:headers:\n${line_repeated_cache}\n"
|
Loading…
Reference in New Issue
Block a user