OLD | NEW |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # Copyright 2015 Google Inc. All Rights Reserved. | 4 # Copyright 2015 Google Inc. All Rights Reserved. |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 """ | 279 """ |
280 Injects meta and link tags into an HTML document. | 280 Injects meta and link tags into an HTML document. |
281 | 281 |
282 Args: | 282 Args: |
283 soup: BeautifulSoup HTML document. Will be modified. | 283 soup: BeautifulSoup HTML document. Will be modified. |
284 ca_manifest: Manifest dictionary of _Chrome App_. | 284 ca_manifest: Manifest dictionary of _Chrome App_. |
285 root_path: Path to the root directory of the web app from this HTML file. | 285 root_path: Path to the root directory of the web app from this HTML file. |
286 This can be either absolute or relative. | 286 This can be either absolute or relative. |
287 html_path: Path to the HTML document being modified. | 287 html_path: Path to the HTML document being modified. |
288 """ | 288 """ |
289 if not soup.head: | |
Matt Giuca
2016/01/29 02:19:26
head = soup.head
if not head:
...
Now you are g
Matthew Alger
2016/01/29 02:41:51
Okay, done. I'm not sure I see the benefit in this
Matt Giuca
2016/01/29 03:04:13
Mostly performance.
You generally want to avoid d
| |
290 head = soup.new_tag('head') | |
291 if soup.html: | |
292 soup.html.insert(0, head) | |
293 else: | |
294 soup.insert(0, head) | |
295 | |
289 # Add manifest link tag. | 296 # Add manifest link tag. |
290 manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME) | 297 manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME) |
291 manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path) | 298 manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path) |
292 soup.head.append(manifest_link) | 299 soup.head.append(manifest_link) |
293 | 300 |
294 # Add meta tags (if they don't already exist). | 301 # Add meta tags (if they don't already exist). |
295 for tag in ('description', 'author', 'name'): | 302 for tag in ('description', 'author', 'name'): |
296 if tag in ca_manifest and not soup('meta', {'name': tag}): | 303 if tag in ca_manifest and not soup('meta', {'name': tag}): |
297 meta = soup.new_tag('meta', content=ca_manifest[tag]) | 304 meta = soup.new_tag('meta', content=ca_manifest[tag]) |
298 meta['name'] = tag | 305 meta['name'] = tag |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 if args.mode == 'config': | 755 if args.mode == 'config': |
749 configuration.generate_and_save(args.output, args.interactive) | 756 configuration.generate_and_save(args.output, args.interactive) |
750 | 757 |
751 elif args.mode == 'convert': | 758 elif args.mode == 'convert': |
752 config = configuration.load(args.config) | 759 config = configuration.load(args.config) |
753 convert_app(args.input, args.output, config, args.force) | 760 convert_app(args.input, args.output, config, args.force) |
754 | 761 |
755 | 762 |
756 if __name__ == '__main__': | 763 if __name__ == '__main__': |
757 sys.exit(main()) | 764 sys.exit(main()) |
OLD | NEW |