Add special case for bundle names in attachment paths

If an attachment path is:

    /foo/<BUNDLE_NAME>/bar/baz.png

That attachment is copied to:

    <HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE_NAME>/bar/baz.png

i.e. the attachment path *after* "/<BUNDLE_NAME>/" is retained.
master
Kaushal Modi 8 years ago
parent a8ae44e692
commit e9e923aa13
  1. 41
      ox-hugo.el
  2. 11
      test/site/content-org/all-posts.org
  3. 2
      test/site/content-org/images-in-content/images-in-content.org
  4. BIN
      test/site/content-org/images-in-content/images/page-bundle-images-in-same-dir/org-copy-2.png
  5. 7
      test/site/content/bundles/page-bundle-a/index.md
  6. 5
      test/site/content/images-in-content/page-bundle-images-in-same-dir/index.md
  7. BIN
      test/site/content/images-in-content/page-bundle-images-in-same-dir/org-copy-2.png
  8. 2
      test/site/themes/bare_min

@ -1859,6 +1859,9 @@ INFO is a plist used as a communication channel."
(exportables org-hugo-external-file-extensions-allowed-for-copying)
(bundle-dir (and (plist-get info :hugo-bundle)
(org-hugo--get-pub-dir info)))
(bundle-name (and bundle-dir ;`bundle-dir'="/foo/bar/" -> `bundle-name'="bar"
(file-name-base
(string-trim-right bundle-dir "/"))))
(static-dir (file-truename
(concat
(file-name-as-directory (plist-get info :hugo-base-dir))
@ -1888,21 +1891,31 @@ INFO is a plist used as a communication channel."
;; return "bar/baz.png".
;; (message "[ox-hugo DBG attch rewrite] path contains static")
(substring path-true (match-end 0)))
((and bundle-dir
(string-match default-directory path-true))
;; This is a page bundle. `default-path' is
;; "<ORG_FILE_DIR>/", `path-true' is
;; "<ORG_FILE_DIR>/bar/baz.png", return
;; "bar/baz.png".
;; (message "[ox-hugo DBG attch rewrite BUNDLE] attch along with Org content: %s"
;; (substring path-true (match-end 0)))
(substring path-true (match-end 0)))
(bundle-dir
;; This is a page bundle. `default-path' is
;; "<ORG_FILE_DIR>/", `path-true' is
;; "/foo/bar/baz.png", return "baz.png".
;; (message "[ox-hugo DBG attch rewrite BUNDLE] attch neither in static nor in Org file dir")
(file-name-nondirectory path))
(cond
((string-match (concat "/" (regexp-quote bundle-name) "/") path-true)
;; This is a page bundle. `bundle-name' is
;; "<BUNDLE_NAME>", `path-true' is
;; "<ORG_FILE_DIR>/bar/<BUNDLE_NAME>/zoo/baz.png",
;; return "zoo/baz.png".
;; (message "[ox-hugo DBG attch rewrite BUNDLE 1] bundle-name: %s" bundle-name)
;; (message "[ox-hugo DBG attch rewrite BUNDLE 1] attch along with Org content: %s"
;; (substring path-true (match-end 0)))
(substring path-true (match-end 0)))
((string-match (regexp-quote default-directory) path-true)
;; This is a page bundle. `default-path' is
;; "<ORG_FILE_DIR>/", `path-true' is
;; "<ORG_FILE_DIR>/bar/baz.png", return
;; "bar/baz.png".
;; (message "[ox-hugo DBG attch rewrite BUNDLE 2] attch along with Org content: %s"
;; (substring path-true (match-end 0)))
(substring path-true (match-end 0)))
(t
;; This is a page bundle. `default-path' is
;; "<ORG_FILE_DIR>/", `path-true' is
;; "/foo/bar/baz.png", return "baz.png".
;; (message "[ox-hugo DBG attch rewrite BUNDLE 3] attch neither in static nor in Org file dir")
(file-name-nondirectory path))))
(t
;; Else, `path-true' is "/foo/bar/baz.png",
;; return "ox-hugo/baz.png". "ox-hugo" is the

@ -1904,11 +1904,12 @@ the copied location inside the bundle:
****** 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]]
****** Page Bundles with images in the same dir as content Org file
|----------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
| Inside =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
|----------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
| =<ORG_FILE_DIR>/bar/baz/foo.png= | =<HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE>/bar/baz/foo.png= | Even if the *outside* path does not have =/static/=, it is still inside the same dir as the Org file, so the directory structure is preserved. |
|----------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
| Inside =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
| =<ORG_FILE_DIR>/bar/baz/foo.png= | =<HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE>/bar/baz/foo.png= | Even if the *outside* path does not have =/static/=, it is still inside the same dir as the Org file, so the directory structure is preserved. |
| =<ORG_FILE_DIR>/bar/<BUNDLE>/baz/foo.png= | =<HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE>/baz/foo.png= | If the file directory path contains ="/<BUNDLE>/"=, the directory structure following that ="/<BUNDLE>/"= is preserved. |
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
See [[/images-in-content/page-bundle-images-in-same-dir/][this other test]] for an example.
*** Bundled page foo
:PROPERTIES:

@ -63,6 +63,8 @@ source Org file of this post.
:END:
** Link to an image in the same dir as this Org file
[[file:gnu.png][file:gnu.png]]
** Link to an image containing this bundle's name in the path
[[file:images/page-bundle-images-in-same-dir/org-copy-2.png][file:images/page-bundle-images-in-same-dir/org-copy-2.png]]
** Link to an image in a subdir in the same dir as this Org file
[[file:images/org-copy-1.png][file:images/org-copy-1.png]]
* Footnotes

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

@ -51,8 +51,9 @@ the copied location inside the bundle:
#### Page Bundles with images in the same dir as content Org file {#page-bundles-with-images-in-the-same-dir-as-content-org-file}
| Inside `<ORG_FILE_DIR>` | Copied-to location inside BUNDLE | Explanation |
|----------------------------------|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `<ORG_FILE_DIR>/bar/baz/foo.png` | `<HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE>/bar/baz/foo.png` | Even if the **outside** path does not have `/static/`, it is still inside the same dir as the Org file, so the directory structure is preserved. |
| Inside `<ORG_FILE_DIR>` | Copied-to location inside BUNDLE | Explanation |
|-------------------------------------------|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `<ORG_FILE_DIR>/bar/baz/foo.png` | `<HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE>/bar/baz/foo.png` | Even if the **outside** path does not have `/static/`, it is still inside the same dir as the Org file, so the directory structure is preserved. |
| `<ORG_FILE_DIR>/bar/<BUNDLE>/baz/foo.png` | `<HUGO_BASE_DIR>/content/<SECTION>/<BUNDLE>/baz/foo.png` | If the file directory path contains `"/<BUNDLE>/"`, the directory structure following that `"/<BUNDLE>/"` is preserved. |
See [this other test](/images-in-content/page-bundle-images-in-same-dir/) for an example.

@ -8,6 +8,11 @@ draft = false
{{< figure src="gnu.png" link="gnu.png" >}}
## Link to an image containing this bundle's name in the path {#link-to-an-image-containing-this-bundle-s-name-in-the-path}
{{< figure src="org-copy-2.png" link="org-copy-2.png" >}}
## Link to an image in a subdir in the same dir as this Org file {#link-to-an-image-in-a-subdir-in-the-same-dir-as-this-org-file}
{{< figure src="images/org-copy-1.png" link="images/org-copy-1.png" >}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

@ -1 +1 @@
Subproject commit 4e952f997f16a7a2fcbc68b538a74f69921c3b5d
Subproject commit 3f7dcc9619d61c005992fb47f60caa2e1f5e3831
Loading…
Cancel
Save