Conversation
…62-search-for-headings
Change to:
Use "Resolves" if only need to upgrade vue-strap.min.js, i.e. no corresponding change is required. |
|
I add a searchbar.vue which will change the vue-strap.min.js. @acjh |
|
How is that relevant? |
|
what do you mean by upgrade vue-strap.min.js |
|
I mean upgrade vue-strap.min.js in the MarkBind/markbind repository. If corresponding change is required, then this PR alone does not resolve the issues. |
|
Ok, get it |
src/Typeahead.vue
Outdated
| filters: { | ||
| highlight (value, phrase) { | ||
| return value.replace(new RegExp('(' + phrase + ')', 'gi'), '<strong>$1</strong>') | ||
| return value.replace(new RegExp('(' + phrase + ')', 'gi'), '<mark>$1</mark>') |
There was a problem hiding this comment.
The indentation here is not necessary (we use 2 spacing per level).
There was a problem hiding this comment.
It is used here in the associated markbind's PR, together with the new filter highlightAndExtract:
The reason is we do the highlighting differently for headings and for keywords.
Headings: Keep everything
Keywords: Only the matching keyword is conserved, with the matching characters highlighted.
There was a problem hiding this comment.
As mentioned last week, shall we create a mark filter instead?
src/searchbar.vue
Outdated
| var query = this.value.toLowerCase() | ||
| var hasHeadingMatch = false | ||
| var title = value.title.toLowerCase() | ||
| var keywords = value.keywords? value.keywords.toLowerCase(): "" |
There was a problem hiding this comment.
Need to have spacing before the ? and :. I.e.
value.keywords ? value.keywords.toLowerCase() : ""
There was a problem hiding this comment.
Also we use single quotes for strings, '' rather than "".
There was a problem hiding this comment.
Since this is a new file, let's use eslint.
Let me see if I can configure it. For now, you can copy-paste it into a .js file in MarkBind.
We can extend this to all custom files (components) later.
src/searchbar.vue
Outdated
| var src = value.src | ||
| if (Object.keys(headings).length !== 0) { | ||
| for (var key in headings) { | ||
| var heading = headings[key].toLowerCase(); |
There was a problem hiding this comment.
Indentation seems to be off here.
src/searchbar.vue
Outdated
| var matches = [] | ||
| var words | ||
| this.data.map(value => { | ||
| var query = this.value.toLowerCase() |
There was a problem hiding this comment.
Instead of having to convert to lower case toLowerCase(), maybe we can use search() instead of index()?
So instead of: heading.indexOf(query), we use heading.search(new RegExp(query, "i"))). The "i" will make the search case-insensitive.
Hopefully this will make the code clearer.
There was a problem hiding this comment.
@nusjzx Is it necessary to modify primitiveData?
src/index.js
Outdated
| import tipBox from './TipBox.vue' | ||
| import trigger from './trigger.vue' | ||
| import typeahead from './Typeahead.vue' | ||
| import searchbar from './Searchbar.vue' |
src/index.js
Outdated
| trigger, | ||
| typeahead | ||
| typeahead, | ||
| searchbar |
src/Typeahead.vue
Outdated
| filters: { | ||
| highlight (value, phrase) { | ||
| return value.replace(new RegExp('(' + phrase + ')', 'gi'), '<strong>$1</strong>') | ||
| return value.replace(new RegExp('(' + phrase + ')', 'gi'), '<mark>$1</mark>') |
src/searchbar.vue
Outdated
| var matches = [] | ||
| var words | ||
| this.data.map(value => { | ||
| var query = this.value.toLowerCase() |
There was a problem hiding this comment.
@nusjzx Is it necessary to modify primitiveData?
src/searchbar.vue
Outdated
| var query = this.value.toLowerCase() | ||
| var hasHeadingMatch = false | ||
| var title = value.title.toLowerCase() | ||
| var keywords = value.keywords? value.keywords.toLowerCase(): "" |
There was a problem hiding this comment.
Since this is a new file, let's use eslint.
Let me see if I can configure it. For now, you can copy-paste it into a .js file in MarkBind.
We can extend this to all custom files (components) later.
|
@acjh 1. the change is used, as we still need highlight filter |
src/searchbar.vue
Outdated
| this.data.map(value => { | ||
| var query = new RegExp(this.value, 'i') | ||
| var hasHeadingMatch = false | ||
| var title = value.title |
There was a problem hiding this comment.
Since we have gotten rid of the .toLowerCase(), the assignment might no longer be necessary, just use value.title below. E.g.:
matches.push({'title': value.title,Same thing for keywords and headings.
src/searchbar.vue
Outdated
| var query = new RegExp(this.value, 'i') | ||
| var hasHeadingMatch = false | ||
| var title = value.title | ||
| var keywords = value.keywords ? value.keywords : '' |
There was a problem hiding this comment.
You can use || instead. I.e.:
const keywords = value.keywords || '';
src/searchbar.vue
Outdated
| for (var key in headings) { | ||
| var heading = headings[key] | ||
| if (heading.search(query) !== -1) { | ||
| hasHeadingMatch = true |
There was a problem hiding this comment.
hasHeadingMatch -> hasMatchingHeading
src/searchbar.vue
Outdated
| primitiveData() { | ||
| if (this.data) { | ||
| var matches = [] | ||
| var words |
There was a problem hiding this comment.
Remove this declaration, declare this below when it is initialized, so it is something like:
const words = keywords ? keywords + title : title
src/searchbar.vue
Outdated
| var matches = [] | ||
| var words | ||
| this.data.map(value => { | ||
| var query = new RegExp(this.value, 'i') |
There was a problem hiding this comment.
if the variable does not change its value after initialization, you should use const instead of var:
const query = new RegExp(this.value, 'i')Same for the rest of the variables below.
| tooltip, | ||
| pic, | ||
| trigger, | ||
| searchbar, |
There was a problem hiding this comment.
The indentation here is tab rather than space. I think your IDE might be set to tabs rather than space?
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [] Documentation update
• [ ] Bug fix
• [ ] New feature
• [x] Enhancement to an existing feature
• [ ] Other, please explain:
Related MarkBind/markbind#162, MarkBind/markbind#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)
highlightAndExtract function will extract the matching results then highlight the phrases.
for jumping to a specific heading, we have one entry for each heading(suggested by Prof Damith).
Thus, Instead of processing on a single string that combines title, keywords and headings, we match headings first, then title and keywords.
Testing instructions:
in vue-strap
npm run buildcopy paste vue-strap.min.js to markbind
After cloning the CS3281 website, go to common/header.md, and replace the use of with :
test on 3281 website