code-hike / codehike

Build rich content websites with Markdown and React
https://codehike.org
MIT License
4.74k stars 146 forks source link

Provide some means to shorten/deduplicate file paths #260

Closed zentol closed 2 years ago

zentol commented 2 years ago

When embedding code from a file one needs to specify a relative path to said file.

Depending on the project structure and language these can become quite long, like ../../projects/project/src/main/java/my/stable/package/prefix/some/more/packagesCode.Java

This makes the .mdx files less legible, requires copying a (usually common) base path into every block, and requires changes to every referencing file if the project structure changes.

This issue is multi-faceted; on the one hand it is about de-duplicating paths within a single file (for example, we reference the same file 5-6 times), and de-duplicating path fragments across files.

pomber commented 2 years ago

Do you have any syntax in mind for that? What would a solution look like?

zentol commented 2 years ago

I thought of something like this:

<CH.Code>
```java Class.java
// from {basePath}/some/path/infix/{pathSuffix)/Class.java

</CH.Code>

where `basePath` and `pathSuffix` would be set in the plugin config in some `vars` map:

{ lineNumbers: false, vars: { basePath: "some/path" pathSuffix: "some/other/path" } }

pomber commented 2 years ago

I understand, but I think this is outside of the scope of Code Hike, at least for now.