| 18 | discarded = False |
| 19 | |
| 20 | def __init__(self, site, source_path): |
| 21 | self.site = site |
| 22 | |
| 23 | # The path where this element should be linked in "base" pages |
| 24 | self.source_path = source_path |
| 25 | |
| 26 | # The URL where this element should be linked in "base" pages |
| 27 | self.link_url = '/{0}'.format(self.source_path) |
| 28 | |
| 29 | if self.site.prettify_urls: |
| 30 | # The URL where this element should be linked in "built" pages |
| 31 | if self.is_html(): |
| 32 | if self.is_index(): |
| 33 | self.final_url = self.link_url.rsplit('index.html', 1)[0] |
| 34 | else: |
| 35 | self.final_url = '{0}/'.format(self.link_url.rsplit('.html', 1)[0]) |
| 36 | else: |
| 37 | self.final_url = self.link_url |
| 38 | |
| 39 | # The path where this element should be built to |
| 40 | if not self.is_html() or self.source_path.endswith('index.html'): |
| 41 | self.build_path = self.source_path |
| 42 | else: |
| 43 | self.build_path = '{0}/{1}'.format(self.source_path.rsplit('.html', 1)[0], 'index.html') |
| 44 | else: |
| 45 | self.final_url = self.link_url |
| 46 | self.build_path = self.source_path |
| 47 | |
| 48 | def is_html(self): |
| 49 | return urllib.parse.urlparse(self.source_path).path.endswith('.html') |