Skip to content

Conversation

@yamgent
Copy link
Member

@yamgent yamgent commented Jun 12, 2018

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [X] Bug fix

Fixes #262.

What is the rationale for this request?
When including files belonging to an inner website, the computation of baseUrl is wrong if the depth of the inclusion is only 1.

What changes did you make? (Give an overview)
Fixed the logic of the algorithm such that the computation of baseUrl is correct regardless of how deep the inclusion is.

Provide some example code that this change will affect:
https://github.com/yamgent/markbind-problems/tree/master/issue_262

Is there anything you'd like reviewers to focus on?
The soundness of the fix.

Testing instructions:

  1. Clone https://github.com/yamgent/markbind-problems.git.
  2. Go to issue_262 directory.
  3. Run markbind serve.
  4. Everything should render with This is cheese's baseUrl: /main_website/inner_site.
    a. In the buggy version, the first entry will show This is cheese's baseUrl: /main_website.

@yamgent
Copy link
Member Author

yamgent commented Jun 12, 2018

Additional writeup:

This is the content that MarkBind generates, before it processes the includes through result => markbinder.resolveBaseUrl(result, fileConfig):


# 262: Broken baseUrl links for inner websites

Version: v1.8.0.

## Include `inner_site/cheese.md`:
<div cwf="C:\Users\Tan Wang Leng\Documents\GitHub\yamgent\markbind-problems\issue_262\index.md" include-path="C:\Users\Tan Wang Leng\Documents\GitHub\yamgent\markbind-problems\issue_262\inner_site\cheese.md">

This is cheese's baseUrl: {{baseUrl}}.

</div>

## Include `inner_site/index.md`:
<div cwf="C:\Users\Tan Wang Leng\Documents\GitHub\yamgent\markbind-problems\issue_262\index.md" include-path="C:\Users\Tan Wang Leng\Documents\GitHub\yamgent\markbind-problems\issue_262\inner_site\index.md">

<div cwf="C:\Users\Tan Wang Leng\Documents\GitHub\yamgent\markbind-problems\issue_262\inner_site\index.md" include-path="C:\Users\Tan Wang Leng\Documents\GitHub\yamgent\markbind-problems\issue_262\inner_site\cheese.md">

This is cheese's baseUrl: {{baseUrl}}.

</div>

</div>

## Expected correct rendering
This is cheese's baseUrl: /main_website/inner_site.

The first {{baseUrl}} generates the wrong URL, while the second {{baseUrl}} is correct.

This is because:

  1. cwf, rather than the include-path, is used to determine if the content belongs from an inner website.
  2. If the depth of the include is not at least 2, then whether we use cwf or include-path to determine 1. does not matter, because it is not processed anyway.

Hence, my PR fixes the two problems mentioned above.

@yamgent yamgent changed the title Fix broken baseUrl links for inner websites Fix broken baseUrl links when referencing inner website's content Jun 12, 2018
@yamgent yamgent changed the title Fix broken baseUrl links when referencing inner website's content baseUrl's value sometimes wrong when referencing inner website's content Jun 12, 2018
@yamgent yamgent force-pushed the 262-broken-links branch from 727a03a to 1befaf7 Compare June 18, 2018 00:56
@yamgent
Copy link
Member Author

yamgent commented Jun 20, 2018

@acjh if you have the time, do feel free to take a look at the PR. :)

@yamgent
Copy link
Member Author

yamgent commented Jun 21, 2018

@nicholaschuayunzhi @acjh Just a heads up, will be getting this merged tomorrow morning, feel free to review this whenever you can. :)

yamgent added 2 commits June 22, 2018 08:39
The current working file path (ATTRIB_CWF) specifies the document that
is including another file (this included file's path is specified with
ATTRIB_INCLUDE_PATH).

When resolving references inside the included file, it should be
resolved with regards to the included file's directory, NOT the working
file's directory.

For example, if the current document is 'abc/index.md', and it includes
another document 'book/some-file.md', then resolving references in
'some-file.md' should be done with the 'book/' directory. not the 'abc/'
directory.

Let's use ATTRIB_INCLUDE_PATH instead of ATTRIB_CWF so that the baseUrl
is not resolved wrongly.
Parser#_rebaseReference() may be called multiple times. The file content
may already have {{hostBaseUrl}} in it due to previous calls to
Parser#_rebaseReference().

The variable {{hostBaseUrl}} is still not defined at this stage.
Undefined variables are replaced by nunjucks with nothing,
resulting in wrong paths.

Let's prevent nunjucks from replacing {{hostBaseUrl}}, by declaring the
variable to be itself, so that the value can be injected later when it
actually exist.
@yamgent yamgent force-pushed the 262-broken-links branch from dd8e7e1 to e3c5d6d Compare June 22, 2018 00:52
@yamgent yamgent merged commit adcdf50 into MarkBind:master Jun 22, 2018
@yamgent yamgent deleted the 262-broken-links branch June 22, 2018 01:10
@yamgent yamgent added this to the v1.8.2 milestone Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

baseUrl's value sometimes wrong when referencing inner website's content

1 participant