Init Spanish translation (#13543)
* Add OWNERS information for sig-docs-es * Add spanish README file * Add Spanish language section * Add headless _common-resources section * Add case-studies section * Add docs section * Add search page * Add overview section * Add main content page * Add i18n strings for Spanish language * Add alexbrand as OWNER and REVIEWER * Add glo-pena as REVIEWER * Add headless include section * Add partners section * Add blog section * Add Code of Conduct manifests * Add supported-doc-versions page * Add community site * Add sitemap * Remove overview section * Add initial home version * Rework phrase * Fix typo * Add update-user-guid-links script * Upload Spanish CoC updated version https://github.com/cncf/foundation/commit/e2a956 * Rework phrase * Fix typo in community index * Fix informal person usage * Translate sitemap page * Add electrocucaracha as REVIEWER * Add landing page for /es/docs * Remove home pages from initial translation * Upload Spanish CoC updated version https://github.com/cncf/foundation/commit/6474dfd * Add more information to the docs landing
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
a03303dca5
commit
f1627103a0
@@ -0,0 +1,85 @@
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
# Finds the documents to rewrite for files that include user-guide-content-moved.md.
|
||||
# Then opens these files and processes the stuff after those lines to figure out where
|
||||
# the line should move to.
|
||||
# Returns a list of ('old/path', 'new/path') tuples.
|
||||
def find_documents_to_rewrite():
|
||||
cmd = "ag --markdown -Q -l \"{% include user-guide-content-moved.md %}\""
|
||||
moved_docs = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().splitlines()
|
||||
|
||||
rewrites = []
|
||||
for doc in moved_docs:
|
||||
location = doc_location(doc)
|
||||
destinations = get_destinations_for_doc(doc)
|
||||
|
||||
if len(destinations) == 0:
|
||||
print("Unable to get possible destinations for %s" % doc)
|
||||
elif len(destinations) > 1:
|
||||
print("%s has multiple potential destinations. Not rewriting links." % doc)
|
||||
else:
|
||||
# print("%s --> %s" % (location, destinations[0]))
|
||||
rewrites.append((location, destinations[0]))
|
||||
|
||||
return rewrites
|
||||
|
||||
# Returns the location of the documentation as we will refer to it in the markdown.
|
||||
# /docs/path/to/foo/index.md are available at /docs/path/to/foo/
|
||||
# /docs/path/to/foo/bar.md are available at /docs/path/to/foo/bar/
|
||||
def doc_location(filename):
|
||||
if filename.endswith('/index.md'):
|
||||
return "/docs/" + filename[:-9] + "/"
|
||||
else:
|
||||
return "/docs/" + filename[:-3] + "/"
|
||||
|
||||
REDIRECT_REGEX = re.compile("^.*\[(.*)\]\((.*)\)$")
|
||||
|
||||
def get_destinations_for_doc(filename):
|
||||
destination_paths = []
|
||||
with open(filename) as f:
|
||||
lines = [line.rstrip('\n').rstrip('\r') for line in f.readlines()]
|
||||
|
||||
# Remove empty lines
|
||||
lines = filter(bool, lines)
|
||||
|
||||
content_moved_index = lines.index("{% include user-guide-content-moved.md %}")
|
||||
|
||||
# Get everything after that line.
|
||||
destinations = lines[content_moved_index + 1:]
|
||||
for destination in destinations:
|
||||
result = REDIRECT_REGEX.match(destination)
|
||||
if not result:
|
||||
return []
|
||||
doc_title = result.group(1) # Unused, can print it out for more info.
|
||||
new_path = result.group(2)
|
||||
destination_paths.append(new_path)
|
||||
|
||||
return destination_paths
|
||||
|
||||
# Given a list of (old/path, new/path) tuples executes a sed command across all files in
|
||||
# to replace (/docs/path/to/old/doc/) with (/docs/path/to/new/doc/).
|
||||
def rewrite_documents(rewrites):
|
||||
cmd = "find . -name '*.md' -type f -exec sed -i.bak 's@(%s)@(%s)@g' '{}' \;"
|
||||
for original, new in rewrites:
|
||||
|
||||
print("%s --> %s" % (original, new))
|
||||
original = original.replace('-', '\-')
|
||||
new = new.replace('-', '\-')
|
||||
|
||||
#print(cmd % (original, new))
|
||||
subprocess.call(cmd % (original, new), shell=True)
|
||||
|
||||
# We can't have in-line replace across multiple files without sudo (I think), so it
|
||||
# creates a lot of backups that we have to delete.
|
||||
def remove_sed_backups():
|
||||
cmd = "find . -name '*.bak' -delete"
|
||||
subprocess.call(cmd, shell=True)
|
||||
|
||||
def main():
|
||||
rewrites = find_documents_to_rewrite()
|
||||
rewrite_documents(rewrites)
|
||||
remove_sed_backups()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user