From cd9263feb0c835b059058b6f6757e64706a457c7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 17 Oct 2023 10:25:18 -0400 Subject: Add (and run) script to auto-regenerate permalink redirects. This deliberately doesn't make any changes in the current formatting or targets (yet); that can come later. It uses the existing yaml format and file. --- mdbook/spec/book.toml | 2 +- mdbook/spec/make_redirects.py | 58 ++++++++++++++++++++++++++++++ mdbook/spec/spec-redirects.yaml | 79 +++++++++++++++++++++++++++++++++++++++++ spec/README.md | 3 -- 4 files changed, 138 insertions(+), 4 deletions(-) create mode 100755 mdbook/spec/make_redirects.py create mode 100644 mdbook/spec/spec-redirects.yaml diff --git a/mdbook/spec/book.toml b/mdbook/spec/book.toml index ee858a8..ee46350 100644 --- a/mdbook/spec/book.toml +++ b/mdbook/spec/book.toml @@ -32,7 +32,7 @@ build-dir = "../../html" "/pt-spec/index.html" = "https://gitweb.torproject.org/torspec.git/tree/pt-spec.txt" "/rend-spec/index.html" = "https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt" "/rend-spec-v2" = "https://gitweb.torproject.org/torspec.git/tree/attic/rend-spec-v2.txt" -"/rend-spec-v3/index.html" = "https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt" +"/rend-spec-v3" = "https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt" "/socks-extensions" = "https://gitweb.torproject.org/torspec.git/tree/socks-extensions.txt" "/srv-spec/index.html" = "https://gitweb.torproject.org/torspec.git/tree/srv-spec.txt" "/tor-fw-helper-spec" = "https://gitweb.torproject.org/torspec.git/tree/attic/tor-fw-helper-spec.txt" diff --git a/mdbook/spec/make_redirects.py b/mdbook/spec/make_redirects.py new file mode 100755 index 0000000..c582505 --- /dev/null +++ b/mdbook/spec/make_redirects.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import yaml, os, re, sys + +def update_file(fname, start_marker, end_marker, replacement): + content = list(open(fname, 'r').readlines()) + startline = content.index(start_marker) + endline = content.index(end_marker) + assert endline > startline + content[startline+1:endline] = replacement + + with open(fname+".tmp", 'w') as f: + f.write("".join(content)) + os.rename(fname+".tmp", fname) + +BOOK_START = "# BEGIN AUTO-GENERATED REDIRECTS\n" +BOOK_END = "# END AUTO-GENERATED REDIRECTS\n" + +README_START = "\n" +README_END = "\n" + +def book_redirects(rs, spec_dir): + lines = [] + for kwd, info in rs.items(): + if os.path.isdir(os.path.join(spec_dir, kwd)): + source = kwd + "/index.html" + else: + source = kwd + target = info['target'] + lines.append( + f'"/{source}" = "{target}"\n' + ) + return "".join(lines) + +def readme_redirects(rs): + lines = [ "
\n" ] + for kwd, info in rs.items(): + target = info['target'] + desc = info['description'] + lines.append(f'
/{kwd}
\n') + lines.append(f'
{target} ({desc})\n') + + lines.append("
\n") + return "".join(lines) + +if __name__ == '__main__': + toplevel = os.path.join(os.path.dirname(sys.argv[0]), "..", "..") + book_fname = os.path.join(toplevel, "mdbook", "spec", "book.toml") + spec_dir = os.path.join(toplevel, "spec") + readme_fname = os.path.join(toplevel, "spec", "README.md") + yaml_fname = os.path.join(toplevel, "mdbook", "spec", "spec-redirects.yaml") + + rs = yaml.load(open(yaml_fname), yaml.Loader)['redirects'] + + update_file(book_fname, BOOK_START, BOOK_END, book_redirects(rs, spec_dir)) + update_file(readme_fname, README_START, README_END, readme_redirects(rs)) + + diff --git a/mdbook/spec/spec-redirects.yaml b/mdbook/spec/spec-redirects.yaml new file mode 100644 index 0000000..26310a7 --- /dev/null +++ b/mdbook/spec/spec-redirects.yaml @@ -0,0 +1,79 @@ +# yamllint disable rule:line-length +--- +# NOTE: that this file is for permalink redirects only. If you want a +# temporary redirect, or a redirect that is not a documentated +# permanent link, do not add it here! + +redirects: + 'address-spec': + target: https://gitweb.torproject.org/torspec.git/tree/address-spec.txt + description: Special Hostnames in Tor + 'bandwidth-file-spec': + target: https://gitweb.torproject.org/torspec.git/tree/bandwidth-file-spec.txt + description: Directory Authority Bandwidth File spec + 'bridgedb-spec': + target: https://gitweb.torproject.org/torspec.git/tree/bridgedb-spec.txt + description: BridgeDB specification + 'cert-spec': + target: https://gitweb.torproject.org/torspec.git/tree/cert-spec.txt + description: Ed25519 certificates in Tor + 'collector-protocol': + target: https://gitweb.torproject.org/collector.git/tree/src/main/resources/docs/PROTOCOL + description: Protocol of CollecTor's File Structure + 'control-spec': + target: https://gitweb.torproject.org/torspec.git/tree/control-spec.txt + description: Tor control protocol, version 1 + 'dir-spec': + target: https://gitweb.torproject.org/torspec.git/tree/dir-spec.txt + description: Tor directory protocol, version 3 + 'dir-list-spec': + target: https://gitweb.torproject.org/torspec.git/tree/dir-list-spec.txt + description: Tor Directory List file format + 'ext-orport-spec': + target: https://gitweb.torproject.org/torspec.git/tree/ext-orport-spec.txt + description: Extended ORPort for pluggable transports + 'gettor-spec': + target: https://gitweb.torproject.org/torspec.git/tree/gettor-spec.txt + description: GetTor specification + 'padding-spec': + target: https://gitweb.torproject.org/torspec.git/tree/padding-spec.txt + description: Tor Padding Specification + 'path-spec': + target: https://gitweb.torproject.org/torspec.git/tree/path-spec.txt + description: Tor Path Specification + 'pt-spec': + target: https://gitweb.torproject.org/torspec.git/tree/pt-spec.txt + description: Tor Pluggable Transport Specification, version 1 + 'rend-spec': + target: https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt + description: Tor Onion Service Rendezvous Specification, Version 2 + 'rend-spec-v2': + target: https://gitweb.torproject.org/torspec.git/tree/attic/rend-spec-v2.txt + description: Tor Onion Service Rendezvous Specification, Version 2 + 'rend-spec-v3': + target: https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt + description: Tor Onion Service Rendezvous Specification, Version 3 + 'socks-extensions': + target: https://gitweb.torproject.org/torspec.git/tree/socks-extensions.txt + description: "Tor's extensions to the SOCKS protocol" + 'srv-spec': + target: https://gitweb.torproject.org/torspec.git/tree/srv-spec.txt + description: Tor Shared Random Subsystem Specification + 'tor-fw-helper-spec': + target: https://gitweb.torproject.org/torspec.git/tree/attic/tor-fw-helper-spec.txt + description: "Tor's (little) Firewall Helper specification" + 'tor-spec': + target: https://gitweb.torproject.org/torspec.git/tree/tor-spec.txt + description: Tor Protocol Specification + 'torbrowser-design': + target: https://2019.www.torproject.org/projects/torbrowser/design/ + description: The Design and Implementation of the Tor Browser + 'version-spec': + target: https://gitweb.torproject.org/torspec.git/tree/version-spec.txt + description: How Tor Version Numbers Work + 'tor-design': + target: https://svn.torproject.org/svn/projects/design-paper/tor-design.pdf + description: "Tor: The Second-Generation Onion Router" + 'walking-onions': + target: https://github.com/nmathewson/walking-onions-wip/tree/master/specs + description: Walking Onions specifications (work in progress) diff --git a/spec/README.md b/spec/README.md index 1aff087..3439afe 100644 --- a/spec/README.md +++ b/spec/README.md @@ -94,7 +94,6 @@ long-term permalinks. > The `gitweb.torproject.org` site is currently deprecated. -
/address-spec
https://gitweb.torproject.org/torspec.git/tree/address-spec.txt (Special Hostnames in Tor) @@ -144,9 +143,7 @@ long-term permalinks.
https://svn.torproject.org/svn/projects/design-paper/tor-design.pdf (Tor: The Second-Generation Onion Router)
/walking-onions
https://github.com/nmathewson/walking-onions-wip/tree/master/specs (Walking Onions specifications (work in progress)) -
- [git repository]: https://gitlab.torproject.org/tpo/core/torspec/ -- cgit v1.2.3-54-g00ecf