|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | import datetime
|
3 | 3 | import json
|
4 |
| -import pathlib |
5 | 4 | import collections
|
6 | 5 | import logging
|
7 | 6 | import os
|
@@ -97,39 +96,39 @@ def vpathto(self, other_version_name):
|
97 | 96 | posixpath.split(self.context["pagename"])[-1]
|
98 | 97 | )
|
99 | 98 |
|
100 |
| - # Find output root |
| 99 | + # Find relative outputdir paths from common output root |
101 | 100 | current_version = self.metadata[self.current_version_name]
|
102 | 101 | other_version = self.metadata[other_version_name]
|
103 |
| - outputroot = os.path.commonpath( |
104 |
| - (current_version["outputdir"], other_version["outputdir"]) |
| 102 | + |
| 103 | + current_outputroot = os.path.abspath(current_version["outputdir"]) |
| 104 | + other_outputroot = os.path.abspath(other_version["outputdir"]) |
| 105 | + outputroot = os.path.commonpath((current_outputroot, other_outputroot)) |
| 106 | + |
| 107 | + current_outputroot = os.path.relpath( |
| 108 | + current_outputroot, start=outputroot |
105 | 109 | )
|
| 110 | + other_outputroot = os.path.relpath(other_outputroot, start=outputroot) |
106 | 111 |
|
107 |
| - current_outputroot = pathlib.PurePath( |
108 |
| - current_version["outputdir"] |
109 |
| - ).relative_to(outputroot) |
110 |
| - other_outputroot = pathlib.PurePath( |
111 |
| - other_version["outputdir"] |
112 |
| - ).relative_to(outputroot) |
113 |
| - |
114 |
| - relative_path_to_outputroot = os.path.join( |
115 |
| - *( |
116 |
| - ".." |
117 |
| - for x in current_outputroot.joinpath( |
118 |
| - self.context["pagename"] |
119 |
| - ).parent.parts |
| 112 | + # Ensure that we use POSIX separators in the path (for the HTML code) |
| 113 | + if os.sep != posixpath.sep: |
| 114 | + current_outputroot = posixpath.join( |
| 115 | + *os.path.split(current_outputroot) |
120 | 116 | )
|
121 |
| - ) |
| 117 | + other_outputroot = posixpath.join(*os.path.split(other_outputroot)) |
122 | 118 |
|
123 |
| - # Find output dir of other version |
124 |
| - outputdir = posixpath.join( |
125 |
| - relative_path_to_outputroot, other_outputroot |
| 119 | + # Find relative path to root of other_version's outputdir |
| 120 | + current_outputdir = posixpath.dirname( |
| 121 | + posixpath.join(current_outputroot, self.context["pagename"]) |
| 122 | + ) |
| 123 | + other_outputdir = posixpath.relpath( |
| 124 | + other_outputroot, start=current_outputdir |
126 | 125 | )
|
127 | 126 |
|
128 | 127 | if not self.vhasdoc(other_version_name):
|
129 |
| - return posixpath.join(outputdir, "index.html") |
| 128 | + return posixpath.join(other_outputdir, "index.html") |
130 | 129 |
|
131 | 130 | return posixpath.join(
|
132 |
| - outputdir, "{}.html".format(self.context["pagename"]) |
| 131 | + other_outputdir, "{}.html".format(self.context["pagename"]) |
133 | 132 | )
|
134 | 133 |
|
135 | 134 |
|
|
0 commit comments