Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide path of the file from which the shortcode was invoked #1793

Closed
agluszak opened this issue Mar 9, 2022 · 2 comments
Closed

Provide path of the file from which the shortcode was invoked #1793

agluszak opened this issue Mar 9, 2022 · 2 comments
Assignees

Comments

@agluszak
Copy link

agluszak commented Mar 9, 2022

I'm trying to write a shortcode which includes a syntax-highlighted code from a file. I'm using the new colocation feature.

My shortcode currently looks like this:

{% set text = load_data(path=path, format="plain") -%}
{% set file_name = path | split(pat="/") | last -%}

```{{ language }}
{{ text }}
```

(Download the source code for this example: [here]({{ file_name }})

Given that file content/lessons/4_enums/enums.rs exists, in content/lessons/4_enums/index.md I write

{{ include_code_sample(path="lessons/4_enums/enums.rs", language="rust") }}

Ideally I'd like to be able to write

{{ include_code_sample(path="enums.rs", language="rust") }}

I think for that it would be necessary to provide the path of the file from which the shortcode was invoked.

Unless there is some other way to achieve that, I would be happy to implement the change myself if you provide some guidance.

@agluszak
Copy link
Author

agluszak commented Mar 9, 2022

It may be related (because of colocation), so I'll ask the question here:
it appears that you cannot use get_url with colocated resources.
In the example above get_url(path="content/lessons/4_enums/index.md") works, but get_url(path="content/lessons/4_enums/enums.rs") does not

@Keats
Copy link
Collaborator

Keats commented Mar 10, 2022

See #1779 for the colocation, it might affect you.

As for adding the map to the shortcode context, it's doable but it's probably better to wait till it's a bit cleaned up: https://github.com/getzola/zola/blob/next/components/rendering/src/context.rs#L34 as right now it only passes the path to the .md file to the context I believe?

@Keats Keats self-assigned this Jan 25, 2023
Keats added a commit that referenced this issue Jan 25, 2023
Keats added a commit that referenced this issue Jan 27, 2023
* Refactor image proc

Closes #2066

* Add colocated_path to shortcodes

Closes #1793
@Keats Keats closed this as completed in 8ba6c1c Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants