Uh oh!
There was an error while loading. Please reload this page.
Support searching for headings - #240
Conversation
acjh
commented
May 23, 2018
Can you add some screenshots? |
yamgent
commented
May 23, 2018
Missing step for testing instruction: After cloning the CS3281 website, go to <searchbar:data="searchData" placeholder="Search" :template="titleTemplate" template-name="title" :on-hit="searchCallback"></searchbar> |
nusjzx
commented
May 23, 2018
acjh
commented
May 23, 2018
Is that generating multiple entries for a single page? Doesn't seem right. |
nusjzx
commented
May 23, 2018
long headings are not truncated, as we have each heading per entry |
nusjzx
commented
May 23, 2018
prof just checked the effects, this is what he suggested |
There was a problem hiding this comment.
Good work implementing the search for headings. Some comments about the commit titles:
Add headings in search data -> Page.js: Collect headings for siteData.json
Highlight matches in search result -> Search: Modify dropdown to highlight heading matches
Use searchbar to replace typeahead -> Search: Replace typeahead with searchbar
Update new syntax for searchbar in userguide -> Docs: Replace typeahead with searchbar
The commit "Merge branch 'master' of https://github.com/MarkBind/markbind into 16…" can be gotten rid of by rebasing the branch to the latest master.
Also some suggestions for improvements:
| searchCallback(match) { | ||
| window.location = `${baseUrl}/${match.src.replace('.md', '.html')}`; | ||
| const page = `${baseUrl}/${match.src.replace('.md', '.html')}`; | ||
| window.location = Object.keys(match.heading).length === 0 ? page : `${page}#${match.heading.id}`; |
There was a problem hiding this comment.
How about:
constpage=`${baseUrl}/${match.src.replace('.md','.html')}`;constanchor=(Object.keys(match.heading).length===0) ? '' : `#${match.heading.id}`;window.location=`${page}${anchor}`;| VueStrap.installEvents(vm); | ||
| } | ||
There was a problem hiding this comment.
@nusjzx This is still not resolved :P. This addition of blank line is not necessary.
damithc
commented
May 23, 2018
I suggested one entry per heading because otherwise there is no way to jump to a specific heading of a page (unless we modify the UI of the typehead component drastically). Need to dogfood this version over cs2103 website to see if the current version is user-friendly. @nusjzx try using real search scenarios over cs2103 website to gauge usability. |
ac5056e to
5583320Compare| VueStrap.installEvents(vm); | ||
| } | ||
There was a problem hiding this comment.
@nusjzx This is still not resolved :P. This addition of blank line is not necessary.
| }); | ||
| VueStrap.installEvents(vm); | ||
| } | ||
| Page.prototype.collectHeadings = function (includedPage) { | ||
| const $ = cheerio.load(includedPage); | ||
| $('h1,h2,h3').map((i, heading) => { |
There was a problem hiding this comment.
This should use forEach rather than map so that we can avoid the return 0;
There was a problem hiding this comment.
Sorry, the correct name should be each() for this case.
damithc
commented
May 25, 2018
nusjzx
commented
May 25, 2018
@damithc noted |
yamgent
commented
May 25, 2018
This PR needs to be rebased to the latest master, there's a conflicting file. |
5b42fae to
6ece5c1Comparedanielbrzn
commented
May 27, 2018
Looked through the PR and the live demo available at https://nusjzx.github.io/website-base/. It's a good start to making the search more functional and user-friendly, especially given that important headings might be hidden behind panels that the user has to click in order to see. Some comments:
|
yamgent
commented
May 28, 2018
I highly suspect it is mainly due to the large data source. If the highlighting of the match is a problem then it also means we are also rendering too many items in the list. Two things we could possibly do to make this less of an issue:
|
damithc
commented
May 28, 2018
Performance improvements can be done as separate PRs if appropriate. |
yamgent
left a comment
There was a problem hiding this comment.
I think this iteration is good.
- Perhaps bolding the matches between the user's query and results might be a better experience for the user instead of highlighting the matches. It might seem a bit jarring to users.
Hmm... I personally find it OK actually, though I guess this is quite subjective, so if Prof finds the style too weird we can definitely change it.
Changes to the original component in MarkBind/vue-strap#30 made this approval no longer valid. I shall wait till the original component gets approved first before getting this re-evaluated.
damithc
commented
May 28, 2018
We'll keep this point in mind. Can tweak later if needed. |
acjh
commented
May 30, 2018
Please change this to:
And update this PR where required. |
| ```html | ||
| <typeahead :data="searchData" placeholder="Search" :template="titleTemplate" template-name="title" :on-hit="searchCallback"></typeahead> | ||
| <searchbar :data="searchData" placeholder="Search" :template="titleTemplate" template-name="title" :on-hit="searchCallback"></searchbar> |
There was a problem hiding this comment.
Can remove :template="titleTemplate" and template-name="title" since we now have defaults.
| <li slot="right"> | ||
| <form class="navbar-form"> | ||
| <typeahead :data="searchData" placeholder="Search" :template="titleTemplate" template-name="title" :on-hit="searchCallback"></typeahead> | ||
| <searchbar :data="searchData" placeholder="Search" :on-hit="searchCallback"></searchbar> |
There was a problem hiding this comment.
Remove additional space in "␣␣:on-hit
| this.frontMatter = {}; | ||
| this.includedFiles = {}; | ||
| this.headings = {}; |
| .then(result => fs.outputFileAsync(this.tempPath, result)) | ||
| .then(() => markbinder.renderFile(this.tempPath, fileConfig)) | ||
| .then((result) => { | ||
| this.collectHeadings(result); |
There was a problem hiding this comment.
+ .then(result => this.collectHeadings(results))
.then((result) => {| "html-include": "HTML include", | ||
| "include-from-another-markbind-site": "Include from another Markbind site", | ||
| "feature-list": "Feature list" | ||
| }, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| $('h1,h2,h3').each((i, heading) => { | ||
| this.headings[$(heading).attr('id')] = $(heading).text(); | ||
| }); | ||
| }; |
There was a problem hiding this comment.
- Move this above
collectIncludedFiles. - Add jsdoc.
acjh
commented
May 31, 2018
@yamgent The changes in setup.js make this PR a breaking change, to be noted in the next release. |
| }; | ||
| /** | ||
| * Records all h1-h3 headings id-text pair into this.headings |
There was a problem hiding this comment.
Records all h1 to h3 headings id-text pair into this.headings
Mentioning id-text pair would reveal too much details imo.
| "html-include": "HTML include", | ||
| "include-from-another-markbind-site": "Include from another Markbind site", | ||
| "feature-list": "Feature list" | ||
| }, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| * Records all h1-h3 headings into this.headings | ||
| * @param includedPage a page with its dependencies included | ||
| */ | ||
| Page.prototype.collectHeadings = function (includedPage) { |
There was a problem hiding this comment.
Should be renderedPage.
/** * Records h1,h2,h3 headings into this.headings * @param renderedPage a page with its headings rendered */Page.prototype.collectHeadings=function(renderedPage){9bc585b to
8b4c768Compareyamgent
commented
Jun 1, 2018
@danielbrzn Mind taking a look at this again, specifically the code? Thanks! :) |
| }; | ||
| /** | ||
| * Records all h1-h3 headings into this.headings |
There was a problem hiding this comment.
@nusjzx Note the change in the first line, from #240 (comment):
/***Recordsh1,h2,h3headingsintothis.headings
damithc
commented
Jun 1, 2018
Alternatively, we can include h4 in search index. |
acjh
commented
Jun 1, 2018
yamgent
commented
Jun 4, 2018
I think it is good to "upgrade" them. If the new headings doesn't look pleasant, then I think the root of the issue is that the style for different headings are not distinct enough from each other, and we should fix that rather than skipping headings. |
yamgent
commented
Jun 4, 2018
@acjh if it is a breaking change, should that make the version become 2.0.0? According to the semantic versioning scheme, since our new setup.js in this PR breaks existing websites if the authors do not make any changes to their HTML code on their navbar, it qualifies as not having a backwards-compatible feature. |
acjh
commented
Jun 4, 2018
A minor version will do. 1.x is still not production-ready for now. |
889548e to
12b0ed1Compare





What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Documentation update
• [ ] Bug fix
• [ ] New feature
• [x] Enhancement to an existing feature
• [ ] Other, please explain:
Resolves#162 and #204
What is the rationale for this request?
highlighting and extracting the search result helps users to identify the results they want easily,
searching for headings and jump to the headings on click helpers users to go to website sections easily.
What changes did you make? (Give an overview)
Follows MarkBind/vue-strap#30 — implementation of highlighting and extracting
while the template is changed in setup.js
jumping to headings: siteData now includes headings also,
collectHeadingscollect h1, h2, h3 headings, and put them in an object where the key is the id , value is the text content. Jumping is done by adding a anchor after the url.Testing instructions:
npm run build