Skip to content

baseUrl's value sometimes wrong when referencing inner website's content - #263

Merged
yamgent merged 2 commits into
MarkBind:masterfrom
yamgent:262-broken-links
Jun 22, 2018
Merged

baseUrl's value sometimes wrong when referencing inner website's content#263
yamgent merged 2 commits into
MarkBind:masterfrom
yamgent:262-broken-links

Conversation

@yamgent

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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`:
<divcwf="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`:
<divcwf="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"><divcwf="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.

@yamgentyamgent changed the title Fix broken baseUrl links for inner websitesFix broken baseUrl links when referencing inner website's contentJun 12, 2018
@yamgentyamgent changed the title Fix broken baseUrl links when referencing inner website's contentbaseUrl's value sometimes wrong when referencing inner website's contentJun 12, 2018
@yamgent

Copy link
Copy Markdown
MemberAuthor

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

@yamgent

Copy link
Copy Markdown
MemberAuthor

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

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 merged commit adcdf50 into MarkBind:masterJun 22, 2018
@yamgent
yamgent deleted the 262-broken-links branch June 22, 2018 01:10
@yamgentyamgent added this to the v1.8.2 milestone Jun 22, 2018
Sign up for freeto 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

@yamgent