Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Minsu Kim
Minsu Kim

Posted on

     

Fix the Bug on Telescope

Introduction

TheTelescope is the open source project that maintains by Seneca College. The Telescope is an open source web servce and client application gathers all blog posts from variety of platforms such as WordPress, Medium, Dev Community, and many others and presenting as timeline.

Issue

before-fix
Theissue is one of blog post contain many lines of<p><br><p> at the end of blog post. This numerous of line break tag that wrap with paragraph tag interrupt view other blog posts.

Fix

The issue is very simple to fix. In the

remove-empty-paragraphs.jsconst cleanWhiteSpace = require('clean-whitespace');module.exports = function (dom) {  if (!(dom && dom.window && dom.window.document)) {    return;  }  dom.window.document.querySelectorAll('p').forEach((p) => {    p.innerHTML = cleanWhiteSpace(p.innerHTML);    const paragraphInnerHTML = p.innerHTML;    if(!paragraphInnerHTML.replace(/&nbsp;/gm,'').trim()) {      p.remove();    }  });};
Enter fullscreen modeExit fullscreen mode

The logic already has been made for the&nbsp non-breaking space. Therefore simply add one more condition|| paragraphInnerHTML.trim() === '<br>' that catch if the<p> contains only<br> tag for remove the

tag.

challenge

The issue supposed to be easily resolved. However there is two things that I have faced the challenge.

  1. Theremove-empty-paragraph.js is never called
  2. Since (1) challenge exists, I do not know my logic is correct.

The reason thatremove-empty-paragraph.js is not called is actually function never get called. I think the empty&nbsp treats as edge case so I think the code was missing. Therefore I have create the code for invoking the function
The second challenge has been resolved with the advice from David who is instructor of this course. His advice is create unit test case for testing my logic is whether pass or fail. Therefore I have created

test('should remove <p><br></p> (line break)', () => {    const htmlData = toDom('<div><p><br></p></div>');    removeEmptyParagraphs(htmlData);    const expectedHtml = '<div></div>';    expect(htmlData.window.document.body.innerHTML).toEqual(expectedHtml);
Enter fullscreen modeExit fullscreen mode

The output is pass! My logic is correct but I do not see the any change on the Telescope running in local. I have no idea why my change does not reflect to the Telescope. So I have asked this issue to our Telescope Slack channel. Thankfully Josue and Duc Bui Manh helped to resolve this issue. They suggested me to delete oldredis-data and re-run the application that also update database to fetch the blog posts. It takes while theelasticSearch crawls the all the blog posts but finally I have the expected result.

after-fix

Conclusion

During the time in Hacktoberfest, I have contributed 4 small projects. It is such a good experience to contribute to large open source project Telescope.

Link

PR

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromMinsu Kim

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp