Merge pull request #394 from chuckwagoncomputing/brokenlinks-refactor
Refactor brokenlinks.sh, fix links now found by it
This commit is contained in:
commit
dc4e7eb376
|
@ -4,7 +4,7 @@ See also [Trigger](Trigger)
|
|||
|
||||
To change your trigger settings, open TunerStudio, Engine->Trigger Configuration.
|
||||
|
||||
# Norman Note
|
||||
## Norman Note
|
||||
|
||||
Cam always goes before crank. For shapes with two wheels, left wheel is top in tuner studio.
|
||||
Also order of channels on engine sniffer should match order of channels on the bottom part of corresponding image.
|
||||
|
@ -245,7 +245,7 @@ VQ30
|
|||
|
||||
VW special understanding of 60/2 with a wide tooth instead of of just missing tooth.
|
||||
|
||||
See also [Universal True 60/2](All-Supported-Triggers.md#602)
|
||||
See also [Universal True 60/2](All-Supported-Triggers#602)
|
||||
|
||||
![VW 60/2](Images/triggers/trigger_20.png)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Disclaimer: the following observations could be really wrong, please let me know if you have better information.
|
||||
|
||||
See also [OEM Connectors - 121 pin](OEM-connectors.md#121-pin)
|
||||
See also [OEM Connectors - 121 pin](OEM-connectors#121-pin)
|
||||
|
||||
There are two kinds of 121 connectors which look pretty much the same but do not mate together unless you use a grinder to massage them a bit.
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ See also [Pulse Lock Connector Product Specification](https://www.te.com/commerc
|
|||
[TE 174917-6](http://www.te.com/catalog/pn/en/174917-6)
|
||||
Escort GT, Ford Festiva, Miata NA6 manual
|
||||
|
||||
The larger plugs are the same as on [the 64 pin](OEM-connectors.md#64-pin).
|
||||
The larger plugs are the same as on [the 64 pin](OEM-connectors#64-pin).
|
||||
|
||||
## 52 pin
|
||||
|
||||
|
@ -318,7 +318,7 @@ terminal 173681
|
|||
|
||||
mitsubishi colt/mirage 1991-1995 year for 1.3, 1.6 and 1.8 engine
|
||||
|
||||
See also [the 48 pin](OEM-connectors.md#48-pin).
|
||||
See also [the 48 pin](OEM-connectors#48-pin).
|
||||
|
||||
For sale @ [eBay Store](http://www.ebay.com/usr/rusefi)
|
||||
|
||||
|
@ -388,7 +388,7 @@ And terminals 173716-1 or 173716-2 and 173630-1 or 173630-2
|
|||
|
||||
## 76 pin center lock
|
||||
|
||||
See also [64 pin nissan center lock](OEM-connectors.md#64-pin-nissan-center-lock)
|
||||
See also [64 pin nissan center lock](OEM-connectors#64-pin-nissan-center-lock)
|
||||
|
||||
[TE 5-174385-5](https://www.te.com/usa-en/product-5-174385-5.html)
|
||||
|
||||
|
|
|
@ -17,6 +17,134 @@ escapeReplace() {
|
|||
}
|
||||
export -f escapeReplace
|
||||
|
||||
# return status:
|
||||
# 0: file is good .md
|
||||
# 1: file is bad or not .md
|
||||
checkurl() {
|
||||
# If it's an internet link, ignore it.
|
||||
# That's beyond the scope of this tool.
|
||||
if echo "$2" | grep -E '^[http|\/]' >/dev/null; then
|
||||
return 1
|
||||
fi
|
||||
# At some point in this scripts development, fixed links to files/images were given the './' prefix.
|
||||
# This didn't really hurt anything, but it's not idiomatic.
|
||||
# I added this to fix the problems I caused, and decided it was worth keeping around.
|
||||
if echo "$2" | grep -E '^\./' >/dev/null; then
|
||||
# NEWLINK is the corrected link
|
||||
NEWLINK=$(echo "$2" | sed 's/^\.\///')
|
||||
# Print the file and the old link
|
||||
echo "In $1:" >&2
|
||||
echo "$2" >&2
|
||||
# Print the options as though they are a list in order to have the same UI as other types of correction
|
||||
echo "$NEWLINK" | cat --number >&2
|
||||
if [ "$SCRIPT" -lt 1 ]; then
|
||||
# Read the user input
|
||||
read -r PICK
|
||||
if [ "$PICK" -eq 1 ]; then
|
||||
# Replace the old link with the new one.
|
||||
# Parentheses are placed around both the old link and new one in order to ensure we replace the link,
|
||||
# and not some other place in the file that happens to use the same words.
|
||||
REPLACE=$(escape '('"$2"'#'"$3"')')
|
||||
REPLACEWITH=$(escapeReplace "$NEWLINK"'#'"$3")
|
||||
sed -i "s/$REPLACE/\($REPLACEWITH\)/" "$1"
|
||||
# print the new URL for use in checkhash
|
||||
echo "$NEWLINK"
|
||||
fi
|
||||
# We don't continue here because the link we fixed might be broken.
|
||||
fi
|
||||
fi
|
||||
# Skip links that are to an .md file and aren't broken.
|
||||
if [ "$(find . -name "$2"".md" 2>/dev/null | wc -l)" -gt 0 ]; then
|
||||
# print the URL for use in checkhash
|
||||
echo "$2"
|
||||
return 0
|
||||
fi
|
||||
# Process links that are not to an .md file.
|
||||
# We need to do this separately because Github/gollum behave differently with different kinds of links.
|
||||
# .md files need the name of the file, without the .md extension.
|
||||
# Everything else needs the path relative to the repo root.
|
||||
if echo "$2" | grep -Ev ".md$" >/dev/null; then
|
||||
# Skip the link if it's not broken.
|
||||
if ls "$2" 2>/dev/null >/dev/null; then
|
||||
return 1
|
||||
fi
|
||||
# Print the filename and the broken link.
|
||||
echo "In $1:" >&2
|
||||
echo "$2" >&2
|
||||
# Build the search term we will look for.
|
||||
# All hyphens and underscores are replaced with asterisks, so we
|
||||
# can find files with mismatched hyphens or underscores.
|
||||
SEARCH='*'$(basename "$2" | sed 's/[-_ ]/*/g')'*'
|
||||
# Search for matching files.
|
||||
FILES=$(find . -iname "$SEARCH")
|
||||
# If there are no files, skip to next link.
|
||||
if [ "$(echo -n "$FILES" | wc -c)" -lt 1 ]; then
|
||||
echo "Could not find" >&2
|
||||
return 1
|
||||
fi
|
||||
# List the potential files, with numbers.
|
||||
echo "$FILES" | cat --number >&2
|
||||
if [ "$SCRIPT" -lt 1 ]; then
|
||||
# Read the user input
|
||||
read -r PICK
|
||||
# If the selection isn't a number, skip to the next link.
|
||||
if ! [[ $PICK =~ ^[0-9]+$ ]]; then
|
||||
return 1
|
||||
fi
|
||||
# Get the selected file path, without the preceding ./
|
||||
FILE=$(echo "$FILES" | head -n "$PICK" | tail -n 1 | sed 's/^\.\///')
|
||||
# Replace the old link with the new one.
|
||||
# Parentheses are placed around both the old link and new one in order to ensure we replace the link,
|
||||
# and not some other place in the file that happens to use the same words.
|
||||
REPLACE=$(escape '('"$2"')')
|
||||
REPLACEWITH=$(escapeReplace "$(basename "$FILE" .md)")
|
||||
sed -i "s/$REPLACE/\($REPLACEWITH\)/" "$1"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
echo "In $1:" >&2
|
||||
echo "$2" >&2
|
||||
# Build the search term we will look for.
|
||||
# All hyphens and underscores are replaced with asterisks, so we
|
||||
# can find files with mismatched hyphens or underscores.
|
||||
SEARCH='*'$(basename "$2" | sed 's/[-_ ]/*/g')'*'
|
||||
# Search for matching files.
|
||||
FILES=$(find . -iname "$SEARCH")
|
||||
# If there are no files, skip to next link.
|
||||
if [ "$(echo -n "$FILES" | wc -c)" -lt 1 ]; then
|
||||
echo "Could not find" >&2
|
||||
return 1
|
||||
fi
|
||||
# List the potential files, with numbers.
|
||||
echo "$FILES" | cat --number >&2
|
||||
if [ "$SCRIPT" -lt 1 ]; then
|
||||
# Read the user input
|
||||
read -r PICK
|
||||
# If the selection isn't a number, skip to the next link.
|
||||
if ! [[ $PICK =~ ^[0-9]+$ ]]; then
|
||||
return 1
|
||||
fi
|
||||
# Get the selected file path, without the preceding ./
|
||||
FILE=$(basename "$(echo "$FILES" | head -n "$PICK" | tail -n 1)" .md)
|
||||
# Replace the old link with the new one.
|
||||
# Parentheses are placed around both the old link and new one in order to ensure we replace the link,
|
||||
# and not some other place in the file that happens to use the same words.
|
||||
REPLACE=$(escape '('"$2"'#'"$3"')')
|
||||
REPLACEWITH=$(escapeReplace "$FILE"'#'"$3")
|
||||
sed -i "s/$REPLACE/\($REPLACEWITH\)/" "$1" >&2
|
||||
echo "$FILE"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
export -f checkurl
|
||||
|
||||
checkhash() {
|
||||
# TODO check hash fragment validity
|
||||
return 0
|
||||
}
|
||||
export -f checkhash
|
||||
|
||||
# Main processing function
|
||||
# Passed the path to a .md file
|
||||
searchfile() {
|
||||
|
@ -24,118 +152,16 @@ searchfile() {
|
|||
# See the end of the function for the grep that finds the links in the file.
|
||||
# We use file descriptor 3, because if we used stdin, the read calls inside this loop would read from that instead of
|
||||
# reading the user's input.
|
||||
while IFS= read -r -u 3 link; do
|
||||
# If it's an internet link, ignore it.
|
||||
# That's beyond the scope of this tool.
|
||||
if echo "$link" | grep -E '^[http|\/]' >/dev/null; then
|
||||
continue
|
||||
while IFS= read -r -u 3 LINK; do
|
||||
URL=$(echo "$LINK" | cut -d '#' -f 1)
|
||||
HASH=$(echo "$LINK" | cut -d '#' -f 2)
|
||||
URLSTATUS=0
|
||||
if [ -n "$URL" ]; then
|
||||
URL=$(checkurl "$1" "$URL" "$HASH")
|
||||
URLSTATUS=$?
|
||||
fi
|
||||
# At some point in this scripts development, fixed links to files/images were given the './' prefix.
|
||||
# This didn't really hurt anything, but it's not idiomatic.
|
||||
# I added this to fix the problems I caused, and decided it was worth keeping around.
|
||||
if echo $link | grep -E '^\./' >/dev/null; then
|
||||
# NEWLINK is the corrected link
|
||||
NEWLINK=$(echo "$link" | sed 's/^\.\///')
|
||||
# Print the file and the old link
|
||||
echo "In $1:"
|
||||
echo "$link"
|
||||
# Print the options as though they are a list in order to have the same UI as other types of correction
|
||||
echo "$NEWLINK" | cat --number
|
||||
if [ "$SCRIPT" -lt 1 ]; then
|
||||
# Read the user input
|
||||
read -r PICK
|
||||
if [ "$PICK" -eq 1 ]; then
|
||||
# Replace the old link with the new one.
|
||||
# Parentheses are placed around both the old link and new one in order to ensure we replace the link,
|
||||
# and not some other place in the file that happens to use the same words.
|
||||
REPLACE=$(escape '('"$link"')')
|
||||
REPLACEWITH=$(escapeReplace "$NEWLINK")
|
||||
sed -i "s/$REPLACE/\($REPLACEWITH\)/" "$1"
|
||||
fi
|
||||
# We don't continue here because the link we fixed might be broken.
|
||||
fi
|
||||
fi
|
||||
# Skip links that are to an .md file and aren't broken.
|
||||
if [ "$(find . -name "$link"".md" 2>/dev/null | wc -l)" -gt 0 ]; then
|
||||
continue
|
||||
fi
|
||||
# Skip links that are to a hash fragment.
|
||||
if echo "$link" | grep "#" >/dev/null; then
|
||||
continue
|
||||
fi
|
||||
# Process links that are not to an .md file.
|
||||
# We need to do this separately because Github/gollum behave differently with different kinds of links.
|
||||
# .md files need the name of the file, without the .md extension.
|
||||
# Everything else needs the path relative to the repo root.
|
||||
if echo "$link" | grep -Ev ".md$" >/dev/null; then
|
||||
# Skip the link if it's not broken.
|
||||
if ls "$link" 2>/dev/null >/dev/null; then
|
||||
continue
|
||||
fi
|
||||
# Print the filename and the broken link.
|
||||
echo "In $1:"
|
||||
echo "$link"
|
||||
# Build the search term we will look for.
|
||||
# All hyphens and underscores are replaced with asterisks, so we
|
||||
# can find files with mismatched hyphens or underscores.
|
||||
SEARCH='*'$(basename "$link" | sed 's/[-_ ]/*/g')'*'
|
||||
# Search for matching files.
|
||||
FILES=$(find . -iname "$SEARCH")
|
||||
# If there are no files, skip to next link.
|
||||
if [ "$(echo -n "$FILES" | wc -c)" -lt 1 ]; then
|
||||
echo "Could not find"
|
||||
continue
|
||||
fi
|
||||
# List the potential files, with numbers.
|
||||
echo "$FILES" | cat --number
|
||||
if [ "$SCRIPT" -lt 1 ]; then
|
||||
# Read the user input
|
||||
read -r PICK
|
||||
# If the selection isn't a number, skip to the next link.
|
||||
if ! [[ $PICK =~ ^[0-9]+$ ]]; then
|
||||
continue
|
||||
fi
|
||||
# Get the selected file path, without the preceding ./
|
||||
FILE=$(echo "$FILES" | head -n "$PICK" | tail -n 1 | sed 's/^\.\///')
|
||||
# Replace the old link with the new one.
|
||||
# Parentheses are placed around both the old link and new one in order to ensure we replace the link,
|
||||
# and not some other place in the file that happens to use the same words.
|
||||
REPLACE=$(escape '('"$link"')')
|
||||
REPLACEWITH=$(escapeReplace "$(basename "$FILE" .md)")
|
||||
sed -i "s/$REPLACE/\($REPLACEWITH\)/" "$1"
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
echo "In $1:"
|
||||
echo "$link"
|
||||
# Build the search term we will look for.
|
||||
# All hyphens and underscores are replaced with asterisks, so we
|
||||
# can find files with mismatched hyphens or underscores.
|
||||
SEARCH='*'$(basename "$link" | sed 's/[-_ ]/*/g')'*'
|
||||
# Search for matching files.
|
||||
FILES=$(find . -iname "$SEARCH")
|
||||
# If there are no files, skip to next link.
|
||||
if [ "$(echo -n "$FILES" | wc -c)" -lt 1 ]; then
|
||||
echo "Could not find"
|
||||
continue
|
||||
fi
|
||||
# List the potential files, with numbers.
|
||||
echo "$FILES" | cat --number
|
||||
if [ "$SCRIPT" -lt 1 ]; then
|
||||
# Read the user input
|
||||
read -r PICK
|
||||
# If the selection isn't a number, skip to the next link.
|
||||
if ! [[ $PICK =~ ^[0-9]+$ ]]; then
|
||||
continue
|
||||
fi
|
||||
# Get the selected file path, without the preceding ./
|
||||
FILE=$(basename "$(echo "$FILES" | head -n "$PICK" | tail -n 1)" .md)
|
||||
# Replace the old link with the new one.
|
||||
# Parentheses are placed around both the old link and new one in order to ensure we replace the link,
|
||||
# and not some other place in the file that happens to use the same words.
|
||||
REPLACE=$(escape '('"$link"')')
|
||||
REPLACEWITH=$(escapeReplace "$FILE")
|
||||
sed -i "s/$REPLACE/\($REPLACEWITH\)/" "$1"
|
||||
if [ -n "$HASH" ] && [ "$URLSTATUS" -eq 0 ]; then
|
||||
checkhash "$1" "$HASH" "$URL"
|
||||
fi
|
||||
# This regex finds links in the file that is passed to searchfile
|
||||
# Results are fed to file descriptor 3 for the reasons previously explained.
|
||||
|
|
Loading…
Reference in New Issue