From bf5dbd767b68ec94f7f50922888d57c193e11d28 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Tue, 30 Jan 2018 09:28:40 -0500 Subject: [PATCH] Fix images linked to images when latter outside static/bundle dir Fixes https://github.com/kaushalmodi/ox-hugo/issues/124 Remove the logic clutter that tried to preserve "file:" before links.. "file:" does not make sense for web pages (may be need to revisit this in future, but for now all existing tests pass). - Add tests for images linked to images when the linked image needs to be copied to static. - Another test similar to above but when the page is a bundle and the linked image needs to be copied to the bundle dir. - Also update test site theme --- ox-hugo.el | 11 ++-------- test/site/content-org/all-posts.org | 15 +++++++++++--- .../content/bundles/page-bundle-a/index.md | 5 +++++ test/site/content/posts/image-links.md | 20 +++++++++++++++++-- test/site/themes/bare_min | 2 +- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/ox-hugo.el b/ox-hugo.el index 0e47aae..d64d790 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1691,15 +1691,8 @@ and rewrite link paths to make blogging more seamless." ;; (message "[ox-hugo-link DBG] link params: %s" link-param-str) ) (concat type ":" raw-path)) - (;; Do not add the "file://" prefix if the raw-path - ;; is in the Hugo "static" dir. - (and (string= type "file") - (let ((static-dir (file-truename - (concat - (file-name-as-directory (plist-get info :hugo-base-dir)) - "static/"))) - (raw-path-true (file-truename raw-path))) - (string-match-p (regexp-quote static-dir) raw-path-true))) + (;; Remove the "file://" prefix. + (string= type "file") (let* ((path1 (org-export-file-uri (funcall link-org-files-as-md raw-path))) (path1 (replace-regexp-in-string "\\`file://" "" path1))) (org-hugo--attachment-rewrite-maybe path1 info))) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 3bfb853..c041560 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -72,14 +72,19 @@ Click below image to jump to the unicorn image. - NOTE :: =file:= has to be used in the *Description component* of the Org link. - ------ - +**** Same link with =#+NAME= specified Here's the same link with =#+NAME= specified.. which should also be clickable. #+NAME: fig__unicorn [[/images/org-mode-unicorn-logo.png][file:/images/org-mode-unicorn-logo.png]] +**** Same link with =file:= in "link" portion of the Org link too +/Note that the =file:= is needed only in the "description" portion to +create a hyperlinked image that links to an image. But having =file:= +in the "link" portion of the Org link too shouldn't hurt./ + +Click below image to jump to the unicorn image. +[[file:/images/org-mode-unicorn-logo.png][file:/images/org-mode-unicorn-logo.png]] *** Link to image outside of standard Hugo =static= directory [[../files-to-be-copied-to-static/static/images/copy-of-unicorn-logo.png]] @@ -107,6 +112,8 @@ copied location inside =static=: - Note :: The =ox-hugo= sub-directory name is because of the default value of =org-hugo-default-static-subdirectory-for-externals=. +***** Same image, but hyperlinked to itself +[[../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png][file:../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png]] ** Image captions :PROPERTIES: :EXPORT_DATE: 2017-07-19 @@ -1843,6 +1850,8 @@ the copied location inside the bundle: |--------------------------+------------------------------------------------------+------------------------------------------------------------------------------------------------------| | =~/temp/bar/baz/foo.png= | =/content/
//foo.png= | Here, as the *outside* path does not have =/static/=, the file is copied directly to the BUNDLE dir. | |--------------------------+------------------------------------------------------+------------------------------------------------------------------------------------------------------| +****** Same image, but hyperlinked to itself +[[../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png][file:../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png]] *** Bundled page foo :PROPERTIES: :EXPORT_FILE_NAME: foo diff --git a/test/site/content/bundles/page-bundle-a/index.md b/test/site/content/bundles/page-bundle-a/index.md index 6c29ffb..1694bb5 100644 --- a/test/site/content/bundles/page-bundle-a/index.md +++ b/test/site/content/bundles/page-bundle-a/index.md @@ -42,3 +42,8 @@ the copied location inside the bundle: | Outside `static` | Copied-to location inside BUNDLE | Explanation | |--------------------------|------------------------------------------------------|--------------------------------------------------------------------------------------------------------| | `~/temp/bar/baz/foo.png` | `/content/
//foo.png` | Here, as the **outside** path does not have `/static/`, the file is copied directly to the BUNDLE dir. | + + +#### Same image, but hyperlinked to itself {#same-image-but-hyperlinked-to-itself} + +[{{
}}](copy-2-of-unicorn-logo.png) diff --git a/test/site/content/posts/image-links.md b/test/site/content/posts/image-links.md index 4bdb326..832ee94 100644 --- a/test/site/content/posts/image-links.md +++ b/test/site/content/posts/image-links.md @@ -51,12 +51,23 @@ NOTE : `file:` has to be used in the **Description component** of the Org link. ---- + +### Same link with `#+NAME` specified {#same-link-with-name-specified} Here's the same link with `#+NAME` specified.. which should also be clickable. - + +[{{
}}](/images/org-mode-unicorn-logo.png) + + +### Same link with `file:` in "link" portion of the Org link too {#same-link-with-file-in-link-portion-of-the-org-link-too} + +_Note that the `file:` is needed only in the "description" portion to +create a hyperlinked image that links to an image. But having `file:` +in the "link" portion of the Org link too shouldn't hurt._ + +Click below image to jump to the unicorn image. [{{
}}](/images/org-mode-unicorn-logo.png) @@ -91,3 +102,8 @@ Note : The `ox-hugo` sub-directory name is because of the default value of `org-hugo-default-static-subdirectory-for-externals`. + + +#### Same image, but hyperlinked to itself {#same-image-but-hyperlinked-to-itself} + +[{{
}}](/ox-hugo/copy-2-of-unicorn-logo.png) diff --git a/test/site/themes/bare_min b/test/site/themes/bare_min index 5e437f1..4ed72d1 160000 --- a/test/site/themes/bare_min +++ b/test/site/themes/bare_min @@ -1 +1 @@ -Subproject commit 5e437f140dfe96c7ceee8eccc6b362c2eb2d6529 +Subproject commit 4ed72d116ff49f5e1bdb853f0c8df8d3727d3b0e