Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search panel headings #351

Merged
merged 2 commits into from
Jul 24, 2018
Merged

Conversation

nusjzx
Copy link
Contributor

@nusjzx nusjzx commented Jul 17, 2018

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

• [ ] Documentation update
• [X] Bug fix
• [ ] New feature
• [ ] Enhancement to an existing feature
• [ ] Other, please explain:

Relates #336

What is the rationale for this request?

  1. Headings in dynamic panels are not included in search result.
  2. panels not expanded should not be searchable.

What changes did you make? (Give an overview)
collect headings from panels which are expanded.

Testing instructions:
1.pull MarkBind/vue-strap#80
2. run npm run build in vue-strap repo
3. copy vue-strap.min.js to markbind repo
4. test on 2103 website.
eg: "pros": the pros and cons entry in the software engineer section are not indexed before(It's a panel header)
"abstraction" : object as abstraction entry is there same as above.

lib/Page.js Outdated
this.collectHeadings($(panel).html());
}
});
this.collectHeadingsInRenderedPage(renderedPage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separation of the methods at this spot doesn't seem to make sense, because the context is broken. If the method is too long, then the panel logic should be the one getting refactored instead (i.e. collectHeadingsFromPanels()).

@yamgent
Copy link
Member

yamgent commented Jul 19, 2018

Currently there's a mismatch in behavior between this PR and MarkBind/vue-strap#80, will wait until MarkBind/vue-strap#80 is fully finished before reviewing resumes.

@yamgent yamgent added s.OnHold and removed s.OnHold labels Jul 19, 2018
@yamgent
Copy link
Member

yamgent commented Jul 19, 2018

I can't search for the heading "Bye" with the markdown below.

Also, it seems that # Hi is only searchable when expanded is specified, but since the heading is always visible, it should always be searchable regardless of whether it is expanded or not?

index.md:

<searchbar :data="searchData" placeholder="Search" :on-hit="searchCallback"></searchbar>

<panel header="# Hi" expanded>
  <markdown>
  ## Bye
  Bye
  </markdown>
</panel>

lib/Site.js Outdated
@@ -522,6 +522,11 @@ Site.prototype.generatePages = function () {
});
return new Promise((resolve, reject) => {
Promise.all(processingFiles)
.then(() => {
this.pages.forEach((page) => {
page.collectHeadings(fs.readFileSync(page.resultPath));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fails because page is a mock object rather than the an actual Page object, so page.resultPath is undefined (class attributes do not get mock).

Perhaps redesign the method such that it is unnecessary for Site.js to call fs.readFileSync(page.resultPath)?

lib/Site.js Outdated
@@ -522,6 +522,12 @@ Site.prototype.generatePages = function () {
});
return new Promise((resolve, reject) => {
Promise.all(processingFiles)
.then((res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The res doesn't seem to be necessary (the result is an undefined array, and is not used by subsequent code), so it can be removed (just .then(() => {)

lib/Page.js Outdated
if (panel.attribs.src) {
const includePath = path.resolve(this.resultPath,
path.relative(this.sourcePath,
path.relative(this.baseUrl, panel.attribs.src)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some implementation error computing the include path. I get this error:

Console:

warning: Error: ENOENT: no such file or directory, open 'C:\Users\other._include_.html'
warning: Error: ENOENT: no such file or directory, open 'C:\Users\other._include_.html'
error: ENOENT: no such file or directory, open 'C:\Users\other._include_.html'

index.md:

<panel header="Included panel" src="other.md" expanded>
</panel>

other.md:

# Other Heading

Other heading

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, @nusjzx please update test_site to make sure that this code is working as intended.

Also some minor nits:

lib/Page.js Outdated

/**
* Records headings inside content into this.headings
* @param content that needs to collect headings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param content that contains the headings

lib/Page.js Outdated
@@ -165,21 +165,52 @@ Page.prototype.prepareTemplateData = function () {
};

/**
* Records h1,h2,h3 headings into this.headings
* @param renderedPage a page with its headings rendered
* Records headings in rendered page into this.headings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the below method's comment:

* Records headings inside rendered page into this.headings

const resultDir = path.dirname(path.join('{{hostBaseUrl}}', path.relative(config.rootPath, src)));
const resultPath = path.join(resultDir, utils.setExtension(path.basename(src), '._include_.html'));
element.attribs.src = fragment ? `${resultPath}#${fragment}` : resultPath;
element.attribs.src = resultPath;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in the rendering of panels with fragments after this line of code is changed. This suggests that the fragment is necessary after all:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nusjzx Btw this bug still exist, I presume you are not done with the PR, right? :P

@nusjzx nusjzx force-pushed the search-panel-headings branch 2 times, most recently from 452386e to 0a1d690 Compare July 23, 2018 18:41
Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent job with the test, quite comprehensive! 👍

<panel header="## Panel without src" expanded>
<markdown>
### panel without src content heading
<markdown>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be the closing tag? </markdown>

@@ -38,4 +38,33 @@ siteNav: site-nav.md
# Include from another Markbind site
<include src="sub_site/index.md" />

# Panel without src
<panel header="## Panel without src" expanded>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The heading inside the panel is the same as the heading outside the panel. Maybe you can omit the heading outside the panel if it is the same as the one inside the panel?

This may be applicable for the ones below too.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, implementation looks good. 👍 Please squash the commits now.

@nusjzx nusjzx force-pushed the search-panel-headings branch from 90e2617 to 090622f Compare July 24, 2018 03:50
@yamgent yamgent added this to the v1.9.2 milestone Jul 24, 2018
@yamgent yamgent merged commit 56ea03c into MarkBind:master Jul 24, 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.

2 participants