Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update map.sh #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions tour/tools/map.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
#!/bin/sh
#!/bin/bash

# Copyright 2011 The Go Authors. All rights reserved.
# Copyright 2011 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# This code parses mapping.old and finds a correspondence from the old
# urls (e.g. #42) to the corresponding path (e.g. /concurrency/3).

function findURL {
title="$1"
file=$(grep -l "* $title\$" *.article)
if [[ -z $file ]]
then
echo "undefined"
return 1
fi
titles=$(grep "^* " $file | awk '{print NR, $0}')
page=$(echo "$titles" | grep "* $title\$" | awk '{print $1}')
if [[ $(echo "$page" | wc -l) -gt "1" ]]
then
echo "multiple matches found for $title; find 'CHOOSE BETWEEN' in the output" 1>&2
page="CHOOSE BETWEEN $page"
fi

page=$(echo $page)
lesson=$(echo "$file" | rev | cut -c 9- | rev)
echo "'/$lesson/$page'"
return 0
find_url() {
title="$1"
file=$(grep -l "* $title$" ./*.article)
if [[ -z $file ]]; then
echo "undefined" >&2
return 1
fi
titles=$(grep "^* " "$file" | awk '{print NR, $0}')
page=$(echo "$titles" | grep "* $title$" | awk '{print $1}')
if [[ $(echo "$page" | wc -l) -gt "1" ]]; then
echo "multiple matches found for $title; find 'CHOOSE BETWEEN' in the output" >&2
page="CHOOSE BETWEEN $page"
fi
page=$(echo "$page")
lesson=$(echo "$file" | sed -E 's|^(.*)/(.*).article$|\2|')
echo "'/$lesson/$page'"
return 0
}

mapping=`cat mapping.old`
mapping=$(cat mapping.old)

pushd ../content
echo "$mapping" | while read page; do
num=$(echo "$page" | awk '{print $1}')
title=$(echo "$page" | sed "s/[0-9]* //")
url=$(findURL "$title")
echo " '#$num': $url, // $title"
done
popd > /dev/null
cd ../content || exit
while read -r page; do
num=$(echo "$page" | awk '{print $1}')
title=$(echo "$page" | cut -d' ' -f2-)
url=$(find_url "$title")
echo " '#$num': $url, // $title"
done <<< "$mapping"
cd - > /dev/null || exit