imgmap.py 974 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python3
  2. # -*- coding: UTF-8 -*-
  3. import os
  4. # This code copies the markdown documents in the /docs folder to the
  5. # /localdocs folder, while converting image links to local links.
  6. # Basically, it makes a version of the readme that can be viewed offline.
  7. # generate the image map
  8. # first, open the imgmap.txt
  9. f = open("imgmap.txt",'r')
  10. s = f.read().split('\n')
  11. f.close()
  12. # Now lets generate a list
  13. imgmap = []
  14. for i in s:
  15. if i != '':
  16. imgmap += [i.split(' ')]
  17. # Now let's loop through all of the .md files in /docs and copy to /localdocs
  18. for root, dirs, files in os.walk(os.path.join("..", "docs")):
  19. for file in files:
  20. if file.endswith(".md"):
  21. fn = os.path.join(root, file)
  22. f = open(fn,'r')
  23. s = f.read()
  24. f.close()
  25. for i in imgmap:
  26. s=s.replace(i[0],"img/"+i[1])
  27. f = open(fn.replace("docs","localdocs"),'w')
  28. f.write(s)
  29. f.close()