forked from qiskit-community/qiskit-textbook
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deployment due to issues with sed in Travis environments
- Loading branch information
1 parent
dad48f7
commit 6f5e7ca
Showing
3 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This script adds the analytics code snippet in 'analytics.html.part' | ||
to all the HTML file (at the very end of the <head> section) inside a | ||
target folder received as its only parameter. | ||
""" | ||
|
||
import os | ||
import sys | ||
import glob | ||
|
||
|
||
def get_analytics_snippet(file_name): | ||
file_path = os.path.join(os.path.dirname(__file__), file_name) | ||
print(f'Obtaining analytics snippet from "{file_path}"') | ||
with open(file_path, encoding='utf8') as snippet: | ||
return snippet.read() | ||
|
||
|
||
def main(target_dir): | ||
analytics_snippet = get_analytics_snippet('analytics.html.part') | ||
replacement = f'{analytics_snippet}</head>' | ||
search_path = os.path.join(os.getcwd(), target_dir) | ||
glob_spec = f'{search_path}/**/*.html' | ||
for file_path in glob.glob(glob_spec, recursive=True): | ||
with open(file_path, encoding='utf8') as html_file: | ||
contents = html_file.read() | ||
|
||
new_contents = contents.replace('</head>', replacement) | ||
|
||
with open(file_path, mode='w') as html_file: | ||
print(f'Adding analytics to "{file_path[len(os.getcwd()) + 1:]}"') | ||
html_file.write(new_contents) | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv[-1]) |
File renamed without changes.