Skip to content

Commit f0dd0e2

Browse files
committed
Support image copying for the homepage branch bundle case
This is the case when both `HUGO_SECTION` and `HUGO_BUNDLE` are `/`. Fixes #155.
1 parent 974d8cd commit f0dd0e2

File tree

7 files changed

+66
-12
lines changed

7 files changed

+66
-12
lines changed

ox-hugo.el

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,11 +1907,18 @@ INFO is a plist used as a communication channel."
19071907
(exportables org-hugo-external-file-extensions-allowed-for-copying)
19081908
(bundle-dir (and (plist-get info :hugo-bundle)
19091909
(org-hugo--get-pub-dir info)))
1910-
(bundle-name (and bundle-dir ;`bundle-dir'="/foo/bar/" -> `bundle-name'="bar"
1911-
(file-name-base
1912-
(if (string-match (concat "\\(?:/\\)\\'") bundle-dir)
1913-
(replace-match "" nil nil bundle-dir)
1914-
bundle-dir))))
1910+
(bundle-name (when bundle-dir
1911+
(let* ((content-dir (file-truename
1912+
(file-name-as-directory (expand-file-name
1913+
"content"
1914+
(file-name-as-directory
1915+
(plist-get info :hugo-base-dir))))))
1916+
(is-home-branch-bundle (string= bundle-dir content-dir)))
1917+
(cond
1918+
(is-home-branch-bundle
1919+
"_home")
1920+
(t ;`bundle-dir'="/foo/bar/" -> `bundle-name'="bar"
1921+
(file-name-base (directory-file-name bundle-dir)))))))
19151922
(static-dir (file-truename
19161923
(concat
19171924
(file-name-as-directory (plist-get info :hugo-base-dir))
@@ -1924,6 +1931,7 @@ INFO is a plist used as a communication channel."
19241931
;; (message "[ox-hugo DBG attch rewrite] path: %s" path)
19251932
;; (message "[ox-hugo DBG attch rewrite] path-true: %s" path-true)
19261933
;; (message "[ox-hugo DBG attch rewrite] bundle-dir: %s" bundle-dir)
1934+
;; (message "[ox-hugo DBG attch rewrite] bundle-name: %s" bundle-name)
19271935
;; (message "[ox-hugo DBG attch rewrite] default-dir: %s" default-directory)
19281936
;; (message "[ox-hugo DBG attch rewrite] dest-dir: %s" dest-dir)
19291937
(if (and (file-exists-p path-true)

test/site/content-org/all-posts.org

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,12 +2033,25 @@ same as those for non-bundle cases.
20332033

20342034
[[../files-to-be-copied-to-static/static/images/copy-of-unicorn-logo-page-bundle.png]]
20352035
***** Source path contains the *bundle name*
2036-
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
2037-
| Inside =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
2038-
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
2039-
| =<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. |
2040-
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
2041-
See [[/images-in-content/page-bundle-images-in-same-dir/][this other test]] for an example.
2036+
See [[/images-in-content/page-bundle-images-in-same-dir/][this other test]] for examples.
2037+
|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------|
2038+
| Inside =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
2039+
|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------|
2040+
| =<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. |
2041+
|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------|
2042+
****** Special case: Home page branch bundle
2043+
In this case, both =HUGO_SECTION= and =HUGO_BUNDLE= values will be
2044+
=/=.
2045+
2046+
So the images to be copied to the *home page branch bundle* i.e. the
2047+
=content/= dir must be placed in a special =_home/= directory. Here
2048+
are some examples:
2049+
|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------|
2050+
| Inside =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
2051+
|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------|
2052+
| =<ORG_FILE_DIR>/bar/_home/baz/foo.png= | =<HUGO_BASE_DIR>/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. |
2053+
| =<ORG_FILE_DIR>/bar/_home/foo.png= | =<HUGO_BASE_DIR>/content/foo.png= | |
2054+
|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------|
20422055
***** Source path contains neither =/static/= nor the *bundle name*
20432056
[[../files-to-be-copied-to-static/foo/copy-2-of-unicorn-logo.png]]
20442057
|----------------------------------+--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------|

test/site/content-org/images-in-content/images-in-content.org

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ source Org file of this post.
6767
[[file:images/page-bundle-images-in-same-dir/org-copy-2.png][file:images/page-bundle-images-in-same-dir/org-copy-2.png]]
6868
** Link to an image in a subdir in the same dir as this Org file
6969
[[file:images/org-copy-1.png][file:images/org-copy-1.png]]
70+
* Home page Branch Bundle with image :homepage:branch:image:bundle:
71+
:PROPERTIES:
72+
:EXPORT_HUGO_SECTION: /
73+
:EXPORT_HUGO_BUNDLE: /
74+
:EXPORT_FILE_NAME: _index
75+
:END:
76+
Image in homepage branch bundle:
77+
78+
[[file:images/_home/org-copy-3.png][file:images/_home/org-copy-3.png]]
7079
* Footnotes
7180
* COMMENT Local Variables :ARCHIVE:
7281
# Local Variables:
7.33 KB
Loading

test/site/content/_index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+++
2+
title = "Home page Branch Bundle with image"
3+
tags = ["homepage", "branch", "image", "bundle"]
4+
draft = false
5+
+++
6+
7+
Image in homepage branch bundle:
8+
9+
{{< figure src="org-copy-3.png" link="org-copy-3.png" >}}

test/site/content/bundles/page-bundle-a/index.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,26 @@ same as those for non-bundle cases.
2828

2929
### Source path contains the **bundle name** {#source-path-contains-the-bundle-name}
3030

31+
See [this other test](/images-in-content/page-bundle-images-in-same-dir/) for examples.
32+
3133
| Inside `<ORG_FILE_DIR>` | Copied-to location inside BUNDLE | Explanation |
3234
|-------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
3335
| `<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. |
3436

35-
See [this other test](/images-in-content/page-bundle-images-in-same-dir/) for an example.
37+
38+
#### Special case: Home page branch bundle {#special-case-home-page-branch-bundle}
39+
40+
In this case, both `HUGO_SECTION` and `HUGO_BUNDLE` values will be
41+
`/`.
42+
43+
So the images to be copied to the **home page branch bundle** i.e. the
44+
`content/` dir must be placed in a special `_home/` directory. Here
45+
are some examples:
46+
47+
| Inside `<ORG_FILE_DIR>` | Copied-to location inside BUNDLE | Explanation |
48+
|----------------------------------------|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
49+
| `<ORG_FILE_DIR>/bar/_home/baz/foo.png` | `<HUGO_BASE_DIR>/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. |
50+
| `<ORG_FILE_DIR>/bar/_home/foo.png` | `<HUGO_BASE_DIR>/content/foo.png` | |
3651

3752

3853
### Source path contains neither `/static/` nor the **bundle name** {#source-path-contains-neither-static-nor-the-bundle-name}

test/site/content/org-copy-3.png

7.33 KB
Loading

0 commit comments

Comments
 (0)