Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. OUTPUT="../../open/restful-api-guidelines/legacy";
  4. RULE=100;
  5.  
  6. rm -rf "${OUTPUT}";
  7.  
  8. for FILE in $(find -name "*.html"); do
  9. TARGET="$(echo ${FILE} | cut -c 44-)";
  10. mkdir -p $(dirname ${OUTPUT}/${TARGET});
  11.  
  12. if [[ "${TARGET}" =~ ^index.html$ ]]; then BASE="";
  13. elif [[ "${TARGET}" =~ ^TOC.html$ ]]; then BASE="./index.html";
  14. else BASE="../index.html"; fi;
  15.  
  16. cat << EOF >> ${OUTPUT}/${TARGET};
  17. <html>
  18. <head>
  19. <script type="text/javascript">
  20. <!--
  21. var target = [];
  22. EOF
  23.  
  24. PAGE="";
  25. for ID in $(cat ${FILE} | grep -o "id=\"[^\"]*\"" | \
  26. grep -v "id=\"section-\"" | sed "s/id=\"//g; s/\"//g;"); do
  27. if [[ "${ID}" =~ ^(must|should|may)- ]]; then
  28. echo " target['${ID}'] = '${BASE}#${RULE}';" >> ${OUTPUT}/${TARGET};
  29. RULE=$((RULE + 1));
  30. else
  31. if [ -z "${PAGE}" ]; then PAGE="${BASE}#${ID}";
  32. echo " target['page'] = '${BASE}#${ID}';" >> ${OUTPUT}/${TARGET};
  33. fi;
  34. echo " target['${ID}'] = '${BASE}#${ID}';" >> ${OUTPUT}/${TARGET};
  35. fi;
  36. done;
  37.  
  38. cat << EOF >> ${OUTPUT}/${TARGET};
  39.  
  40. var fragment = window.location.href.split('#')[1];
  41. if (!fragment || !target[fragment]) { fragment = 'page' }
  42. window.location = target[fragment];
  43.  
  44. //-->
  45. </script>
  46. </head>
  47.  
  48. <body>
  49. You should be redirected to the new location of this page immediately.
  50. Please check that JavaScript has been enabled in your browser, if you
  51. are not redirected automatically.
  52. </body>
  53. </html>
  54. EOF
  55.  
  56. done;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement