diff --git a/ox-hugo.el b/ox-hugo.el index a9b1fbd..f8b991b 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1907,11 +1907,18 @@ 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 - (if (string-match (concat "\\(?:/\\)\\'") bundle-dir) - (replace-match "" nil nil bundle-dir) - bundle-dir)))) + (bundle-name (when bundle-dir + (let* ((content-dir (file-truename + (file-name-as-directory (expand-file-name + "content" + (file-name-as-directory + (plist-get info :hugo-base-dir)))))) + (is-home-branch-bundle (string= bundle-dir content-dir))) + (cond + (is-home-branch-bundle + "_home") + (t ;`bundle-dir'="/foo/bar/" -> `bundle-name'="bar" + (file-name-base (directory-file-name bundle-dir))))))) (static-dir (file-truename (concat (file-name-as-directory (plist-get info :hugo-base-dir)) @@ -1924,6 +1931,7 @@ INFO is a plist used as a communication channel." ;; (message "[ox-hugo DBG attch rewrite] path: %s" path) ;; (message "[ox-hugo DBG attch rewrite] path-true: %s" path-true) ;; (message "[ox-hugo DBG attch rewrite] bundle-dir: %s" bundle-dir) + ;; (message "[ox-hugo DBG attch rewrite] bundle-name: %s" bundle-name) ;; (message "[ox-hugo DBG attch rewrite] default-dir: %s" default-directory) ;; (message "[ox-hugo DBG attch rewrite] dest-dir: %s" dest-dir) (if (and (file-exists-p path-true) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 42f56f3..41acd80 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -2033,12 +2033,25 @@ same as those for non-bundle cases. [[../files-to-be-copied-to-static/static/images/copy-of-unicorn-logo-page-bundle.png]] ***** Source path contains the *bundle name* -|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------| -| Inside == | Copied-to location inside BUNDLE | Explanation | -|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------| -| =/bar//baz/foo.png= | =/content/
//baz/foo.png= | If the file directory path contains ="//"=, the directory structure following that ="//"= is preserved. | -|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------| -See [[/images-in-content/page-bundle-images-in-same-dir/][this other test]] for an example. +See [[/images-in-content/page-bundle-images-in-same-dir/][this other test]] for examples. +|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------| +| Inside == | Copied-to location inside BUNDLE | Explanation | +|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------| +| =/bar//baz/foo.png= | =/content/
//baz/foo.png= | If the file directory path contains ="//"=, the directory structure following that ="//"= is preserved. | +|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------| +****** Special case: Home page branch bundle +In this case, both =HUGO_SECTION= and =HUGO_BUNDLE= values will be +=/=. + +So the images to be copied to the *home page branch bundle* i.e. the +=content/= dir must be placed in a special =_home/= directory. Here +are some examples: +|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Inside == | Copied-to location inside BUNDLE | Explanation | +|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| =/bar/_home/baz/foo.png= | =/content/baz/foo.png= | If the page is the home page branch bundle, and the file directory path contains ~"/_home/"~, the directory structure following that ~"/_home/"~ is preserved. | +| =/bar/_home/foo.png= | =/content/foo.png= | | +|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------| ***** Source path contains neither =/static/= nor the *bundle name* [[../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png]] |----------------------------------+--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------| diff --git a/test/site/content-org/images-in-content/images-in-content.org b/test/site/content-org/images-in-content/images-in-content.org index dadec6e..26e7809 100644 --- a/test/site/content-org/images-in-content/images-in-content.org +++ b/test/site/content-org/images-in-content/images-in-content.org @@ -67,6 +67,15 @@ source Org file of this post. [[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]] +* Home page Branch Bundle with image :homepage:branch:image:bundle: +:PROPERTIES: +:EXPORT_HUGO_SECTION: / +:EXPORT_HUGO_BUNDLE: / +:EXPORT_FILE_NAME: _index +:END: +Image in homepage branch bundle: + +[[file:images/_home/org-copy-3.png][file:images/_home/org-copy-3.png]] * Footnotes * COMMENT Local Variables :ARCHIVE: # Local Variables: diff --git a/test/site/content-org/images-in-content/images/_home/org-copy-3.png b/test/site/content-org/images-in-content/images/_home/org-copy-3.png new file mode 100644 index 0000000..e76f136 Binary files /dev/null and b/test/site/content-org/images-in-content/images/_home/org-copy-3.png differ diff --git a/test/site/content/_index.md b/test/site/content/_index.md new file mode 100644 index 0000000..964d11f --- /dev/null +++ b/test/site/content/_index.md @@ -0,0 +1,9 @@ ++++ +title = "Home page Branch Bundle with image" +tags = ["homepage", "branch", "image", "bundle"] +draft = false ++++ + +Image in homepage branch bundle: + +{{< figure src="org-copy-3.png" link="org-copy-3.png" >}} diff --git a/test/site/content/bundles/page-bundle-a/index.md b/test/site/content/bundles/page-bundle-a/index.md index 92f5d48..e7456d8 100644 --- a/test/site/content/bundles/page-bundle-a/index.md +++ b/test/site/content/bundles/page-bundle-a/index.md @@ -28,11 +28,26 @@ same as those for non-bundle cases. ### Source path contains the **bundle name** {#source-path-contains-the-bundle-name} +See [this other test](/images-in-content/page-bundle-images-in-same-dir/) for examples. + | Inside `` | Copied-to location inside BUNDLE | Explanation | |-------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------| | `/bar//baz/foo.png` | `/content/
//baz/foo.png` | If the file directory path contains `"//"`, the directory structure following that `"//"` is preserved. | -See [this other test](/images-in-content/page-bundle-images-in-same-dir/) for an example. + +#### Special case: Home page branch bundle {#special-case-home-page-branch-bundle} + +In this case, both `HUGO_SECTION` and `HUGO_BUNDLE` values will be +`/`. + +So the images to be copied to the **home page branch bundle** i.e. the +`content/` dir must be placed in a special `_home/` directory. Here +are some examples: + +| Inside `` | Copied-to location inside BUNDLE | Explanation | +|----------------------------------------|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `/bar/_home/baz/foo.png` | `/content/baz/foo.png` | If the page is the home page branch bundle, and the file directory path contains `"/_home/"`, the directory structure following that `"/_home/"` is preserved. | +| `/bar/_home/foo.png` | `/content/foo.png` | | ### Source path contains neither `/static/` nor the **bundle name** {#source-path-contains-neither-static-nor-the-bundle-name} diff --git a/test/site/content/org-copy-3.png b/test/site/content/org-copy-3.png new file mode 100644 index 0000000..e76f136 Binary files /dev/null and b/test/site/content/org-copy-3.png differ