Skip to content

Commit

Permalink
Support image copying for the homepage branch bundle case
Browse files Browse the repository at this point in the history
This is the case when both `HUGO_SECTION` and `HUGO_BUNDLE` are `/`.

Fixes #155.
  • Loading branch information
kaushalmodi committed Apr 23, 2018
1 parent 974d8cd commit f0dd0e2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
18 changes: 13 additions & 5 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
25 changes: 19 additions & 6 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -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 =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
|-------------------------------------------+--------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------|
| =<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.
See [[/images-in-content/page-bundle-images-in-same-dir/][this other test]] for examples.
|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------|
| Inside =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------|
| =<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. |
|-------------------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------|
****** 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 =<ORG_FILE_DIR>= | Copied-to location inside BUNDLE | Explanation |
|----------------------------------------+---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| =<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. |
| =<ORG_FILE_DIR>/bar/_home/foo.png= | =<HUGO_BASE_DIR>/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]]
|----------------------------------+--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
9 changes: 9 additions & 0 deletions test/site/content-org/images-in-content/images-in-content.org
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/site/content/_index.md
Original file line number Diff line number Diff line change
@@ -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" >}}
17 changes: 16 additions & 1 deletion test/site/content/bundles/page-bundle-a/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<ORG_FILE_DIR>` | Copied-to location inside BUNDLE | Explanation |
|-------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| `<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.

#### 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 `<ORG_FILE_DIR>` | Copied-to location inside BUNDLE | Explanation |
|----------------------------------------|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `<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. |
| `<ORG_FILE_DIR>/bar/_home/foo.png` | `<HUGO_BASE_DIR>/content/foo.png` | |


### Source path contains neither `/static/` nor the **bundle name** {#source-path-contains-neither-static-nor-the-bundle-name}
Expand Down
Binary file added test/site/content/org-copy-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0dd0e2

Please sign in to comment.