Repository: getnikola/nikola

Issue:
URL_TYPE option fails for sites deployed outside root folder
`SITE_URL = 'http://getnikola.com/subsite/'`

with `URL_TYPE = 'full_path'` (snippets of index.html):

``` html
    <link rel="canonical" href="http://getnikola.com/index.html">
        <a class="navbar-brand" href="http://getnikola.com/">Demo Site</a>
                <li><a href="/archive.html">Archives</a>
                </li><li><a href="/categories/index.html">Tags</a>
                </li><li><a href="/rss.xml">RSS</a>
```

with `URL_TYPE = 'absolute'`:

``` html
    <link rel="canonical" href="http://getnikola.com/index.html">
        <a class="navbar-brand" href="http://getnikola.com/">Demo Site</a>
                <li><a href="http://getnikola.com/archive.html">Archives</a>
                </li><li><a href="http://getnikola.com/categories/index.html">Tags</a>
                </li><li><a href="http://getnikola.com/rss.xml">RSS</a>
```

No links are correct.



Discussion:
Also, `nikola check -l` needs to take `URL_TYPE` into consideration.


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -725,7 +725,8 @@ def url_replacer(self, src, dst, lang=None):
                 dst = urljoin(self.config['BASE_URL'], dst.lstrip('/'))
                 return dst
             elif self.config.get('URL_TYPE') == 'full_path':
-                return dst
+                dst = urljoin(self.config['BASE_URL'], dst.lstrip('/'))
+                return urlparse(dst).path
             else:
                 return "#"
 
@@ -737,8 +738,13 @@ def url_replacer(self, src, dst, lang=None):
             return dst
 
         if self.config.get('URL_TYPE') in ('full_path', 'absolute'):
-            if self.config.get('URL_TYPE') == 'absolute':
-                dst = urljoin(self.config['BASE_URL'], dst.lstrip('/'))
+            dst = urljoin(self.config['BASE_URL'], dst.lstrip('/'))
+            if self.config.get('URL_TYPE') == 'full_path':
+                parsed = urlparse(urljoin(self.config['BASE_URL'], dst.lstrip('/')))
+                if parsed.fragment:
+                    dst = '{0}#{1}'.format(parsed.path, parsed.fragment)
+                else:
+                    dst = parsed.path
             return dst
 
         # Now both paths are on the same site and absolute
diff --git a/nikola/plugins/command/check.py b/nikola/plugins/command/check.py
--- a/nikola/plugins/command/check.py
+++ b/nikola/plugins/command/check.py
@@ -162,7 +162,8 @@ def analyze(self, task, find_sources=False):
                 if url_type == 'rel_path':
                     target_filename = os.path.abspath(
                         os.path.join(os.path.dirname(filename), unquote(target)))
-                elif url_type == 'absolute':
+
+                elif url_type in ('full_path', 'absolute'):
                     target_filename = os.path.abspath(
                         os.path.join(os.path.dirname(filename), parsed.path))
                     if parsed.path.endswith('/'):  # abspath removes trailing slashes


Test patch:
diff --git a/tests/test_integration.py b/tests/test_integration.py
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -332,6 +332,27 @@ def test_index_in_sitemap(self):
         self.assertTrue('<loc>http://getnikola.com/foo/index.html</loc>' in sitemap_data)
 
 
+class TestCheckFullPathSubFolder(TestCheckAbsoluteSubFolder):
+    """Validate links in a site which is:
+
+    * built in URL_TYPE="full_path"
+    * deployable to a subfolder (BASE_URL="http://getnikola.com/foo/")
+    """
+
+    @classmethod
+    def patch_site(self):
+        conf_path = os.path.join(self.target_dir, "conf.py")
+        with codecs.open(conf_path, "rb", "utf-8") as inf:
+            data = inf.read()
+            data = data.replace('SITE_URL = "http://getnikola.com/"',
+                                'SITE_URL = "http://getnikola.com/foo/"')
+            data = data.replace("# URL_TYPE = 'rel_path'",
+                                "URL_TYPE = 'full_path'")
+        with codecs.open(conf_path, "wb+", "utf8") as outf:
+            outf.write(data)
+            outf.flush()
+
+
 class TestCheckFailure(DemoBuildTest):
     """The demo build should pass 'nikola check'"""