asciidoctor / asciidoctor-intellij-plugin

AsciiDoc plugin for products on the IntelliJ platform (IDEA, RubyMine, etc)
https://intellij-asciidoc-plugin.ahus1.de/
Apache License 2.0
347 stars 146 forks source link

Preview showing content from another project which is in the same directory #1671

Open abogdanov85 opened 1 month ago

abogdanov85 commented 1 month ago

Hi all! That is my problem: I have two different Antora projects (each with its own playbook) which are stored in the same parent directory (we use them to make multi-language documentation).

So the structure is like this:

docs/
  antora-playbook-en.yml
  antora-playbook-ru.yml
  documentation-en/
    antora.yml
    modules/
      ROOT/
        nav.adoc
      pages/
  documentation-ru/
    antora.yml
    modules/
       ROOT/
         nav.adoc
       pages/

In antora-playbook-en.yml we have start_path: documentation-en. In antora-playbook-ru.yml we have start_path: documentation-ru.

Almost all of the adoc files in en pages and ru pages have the same names.

When we build it we just run Antora two times independently (with different playbooks) and everything works great. But the problem is when our authors open nav.adoc locally in Intellij app the render for xref links to pages is for another folder! For example docs/documentation-ru/modules/ROOT/nav.adoc is rendered with links to docs/documentation-en/modules/ROOT/pages/... and vice versa! The links are like this: * xref:about.adoc (the file is located in modules/ROOT/pages/about.adoc in both ru and en folders)

Is there any way to set the start_path locally inside the documentation-ru and documentation-en so that the links are rendered inside these folders? I guess I can set up something like asciidoctorconfig file but I don't understand what I should write in it.

ahus1 commented 1 month ago

Thank you for sharing this setup. The way it could work with the plugin is the following:

This will IMHO work if you have a version defined in your components, and don't use version-less ones.

It is a bit hard to describe in just text. Ff you could prepare an example repository with some real files, I can have a look and could provide more specific advice.

abogdanov85 commented 1 month ago

Thank you for sharing this setup. The way it could work with the plugin is the following:

* Use two different component versions in the component descriptor like `1.0-ru` and `1.0-en`. Then the links would only be relative within the same component.

This will IMHO work if you have a version defined in your components, and don't use version-less ones.

It is a bit hard to describe in just text. Ff you could prepare an example repository with some real files, I can have a look and could provide more specific advice.

Yes that solved the problem! Thank you!

But just for clarity - we don't really use the versions in antora.yml and we can keep them different (and now we will) but what if we had to keep them the same? The solution wouldn't exist in this case?

ahus1 commented 1 month ago

what if we had to keep [the version] the same?

The .asciidoctorconfig files won't help you here.

One thing that would possibly work: Place the playbook and the component for each language in a separate folder, and you would open those two folders in separate IDE windows. This is probably not as convenient as the previous solution.

A future version of the plugin might support the start_path, but that would be quite some rework about the internal wiring. In a lot of setups I've seen the playbook in a separate Git repository, so the IDE usually sees a Git repository with lot of components and no playbook in sight.

I suppose your question is now answered. Is it ok to close this issue?

abogdanov85 commented 1 month ago

Yes thanks! But I have one more related question. In the same setup (which I described above) we have another problem: we have an attribute language defined in playbook files (with values ru and en). And when we try to use this attribute in the adoc files it works after building the projects but it doesn't work in preview. When trying to preview adoc with {language} in the source text we get ru value in both project folders but we expect to get ru inside documentation-ru folder and en inside documentation-en folder.

Can we fix it somehow for preview in Intellij? I tried to define the attribute in antora.yml files but it doesn't work. Of course we always can define it once again in some file inside documentation folders and include this file to all other adoc files in their attribute section. But is there any easier way (without adding anything to all the adoc files)?

ahus1 commented 1 month ago

If the attribute is defined in the two playbooks with different values, the preview ignores it as it can't decide which to use.

Defining it in the component will not work while you keep it in the playbook, as the playbook takes precedence. There is also soft and hard set/unset, which add a layer of complexity.

IMHO you have at least two options here:

  1. Remove the attribute from the playbooks, and add it to the components
  2. Keep it in the playbook, and use an .asciidoctorconfig file to define the attribute only for the preview of IntelliJ.

Again, as mentioned before, an example GitHub project helps to explore options.

abogdanov85 commented 4 weeks ago

If the attribute is defined in the two playbooks with different values, the preview ignores it as it can't decide which to use.

Defining it in the component will not work while you keep it in the playbook, as the playbook takes precedence. There is also soft and hard set/unset, which add a layer of complexity.

IMHO you have at least two options here:

1. Remove the attribute from the playbooks, and add it to the components

2. Keep it in the playbook, and use an `.asciidoctorconfig` file to define the attribute only for the preview of IntelliJ.

Again, as mentioned before, an example GitHub project helps to explore options.

Thanks for your help once again. I tried to make .asciidoctorconfig files in documentation-ru and documentation-en folders and set the language attribute to ru and en there. The result is zero - render doesn't change. It is still ru in both folders.

I made a test copy of our set up in a separate repo as you asked: https://github.com/abogdanov85/Antora_IntelliJ_test

So now language attribute is rendered as ru in both documentation-ru and documentation-en adoc pages. And I can see that test attribute which is defined only in .asciidoctorconfig is rendered so the preview engine is taking attributes from it but it doesn't overwrite it if it's defined in playbook.

I hope you can reproduce this behavior in my example. I cannot share the real repo because it's privilleged. Sorry for that! If you need more details please write here what you need.