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

Better default titles in search: Remove file format ending #1826

Merged
merged 5 commits into from
Mar 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vue-components/src/Searchbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
headingKeywords,
} = entry;
const keywords = entry.keywords || '';
const displayTitle = title || src;
const displayTitle = title || src.substring(0, src.lastIndexOf('.'));
Copy link
Contributor

@ryoarmanda ryoarmanda Mar 17, 2022

Choose a reason for hiding this comment

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

Although not a major issue considering how the normal situation would be like, this would give unexpected results when the file has no extensions (index would be presented as an empty string) or "double" extensions (index.tar.gz would be presented as index.tar)

The latter case seems a bit unlikely to be passed on in normal development situation so I guess it's okay to not cover that (let me know if you feel otherwise though!), but it's good fault-tolerance if we can handle the former case, so it still returns the file name.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the latter case, If there is a file of type .tar.gz, will the search check the content of such files, or, will it be useful for the search to check the content of such files? I am guessing not really, so I think it is fine since typical files that we are getting the content from are .md or .html.

Not too sure about the search implementation and hence cant comment on the formal case/other possible cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I have delved in a little bit on how we include pages and the search, and looks like the latter case (and probably the former too) can be reasonably ignored 😅

Search data comes from siteData.json, which is written by Site, that includes data from Site.pages, which in turn is collected from site.json properties (pages, globs, and the likes). I guess we can reasonably believe that search results come from page files and not any arbitrary file. As our page files are of the normal extension form (.md and .html), then we can assume that the latter case would not happen.

By extension (heh), the former case shouldn't really happen as well. But I still think it's good to be safe rather than encountering a case where the result are empty strings one day. 😄

Copy link
Contributor Author

@kaixin-hc kaixin-hc Mar 18, 2022

Choose a reason for hiding this comment

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

I investigated this suggestion more as well, and found the following code in NodeProcessor.

      const fileExt = path.extname(file);
      if (fsUtil.isMarkdownFileExt(fileExt)) {
        const renderedContent = this.markdownProcessor.renderMd(content);
        // Wrap with <root> as $.remove() does not work on top level nodes
        parser.parseComplete(`<root>${renderedContent}</root>`);
      } else if (fileExt === '.html') {
        parser.parseComplete(`<root>${content}</root>`);
      } else {
        const error = new Error(`Unsupported File Extension: '${fileExt}'`);
        reject(error);
      }

In other words, MarkBind only supports .html or .md. If you deliberately include a 'page' which doesn't have a supported file format ending, the Unsupported File Extension: error is thrown and the website cannot build at all.

So I think both the former and the latter case are invalid inputs that will safely never happen under the current implementation 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the deeper investigation @kaixin-hc, we can safely use this implementation then 😄


const pageSearchTargets = [
displayTitle,
Expand Down