Import code from text archive in docs.md

Hello friends!

I am new to grav and I am really fascinated, congratulations to everyone !!!

After browsing the documentation, (the closest I found was the following https://learn.getgrav.org/16/content/media), I was wondering if there is any possibility to import a text file within a quote from code (inside code xxx).

I explain the purpose so that it is better understood.

I would like to have a documentation page that was in .md:

Compilation of YAML files

General description blablablaba …

With this yaml a DeployConfig rises

file: codes/DeployConfig/first.yaml

And that the content of the yaml (let’s imagine a file of 100 lines) was imported on the page in .md.

In this way you could keep a simpler main page (in long files) and at the same time have the original yaml files ready to use, which would facilitate its updating and maintenance.

Is there any possibility of doing it allowing these files to be indexed by the search?

Thank you!!
I did not find anything similar in google or in the forum, (my level of English is not very high).

A greeting!!

Hello again friends,

Wow!

Investigating the plugins, I stumbled across this one at the bottom of the list, which by chance partially solves the problem.

I say partially since it does not index the content in the searches (not in TNTSearch either) and also shows <pre> <code> type tags at the beginning and end.

I imported it with:

[plugin: filesource] (dir1/first.yaml)

Outcome:

Any idea to be able to index the content and make it appear in the search?

Any ideas to remove <pre> <code>?

Thank you!!!

Hello again friends,

I have managed to remove the indicated in the last post commenting on the following lines … plugins/filesource/filesource.php

                $req_file = $page->path() . "/" . $filename;
                /*$replace_header = "<pre><code>";
                $replace_footer = "</code></pre>";*/
                $replace_content = file_get_contents($req_file);

It only remains … Any idea to index the content of my file in searches? This is still not clear to me.

Thank you,
Cheers!!!

Please wrap your code snippets in triple backticks so it get’s a lot more readable.

Assuming that your source files are YAML files you could try to modify the Grav Import Plugin. The modification would be to bypass the YAML filename specification in a Grav page and just loop through all your YAML files. You’’ end up with a bunch of Grav pages with your YAML text in the page’s frontmatter. Then you can process these data in Twig templates as you like.