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

Move more parsing of strings and html server-side #575

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

drewvolz
Copy link
Member

@drewvolz drewvolz commented Oct 30, 2021

Impacted endpoints

  • Calendars
  • Orgs
  • Jobs
  • Streams
  • Food menus (uses titlecase)

Todo

Copy link
Member

@hawkrives hawkrives left a comment

Choose a reason for hiding this comment

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

When possible, I'd like to use the JSDom functions instead of htmlparser2

return str.replace(/<[^>]*>/gu, ' ')
}

export function fastGetTrimmedText(str) {
Copy link
Member

Choose a reason for hiding this comment

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

Since we have JSDOM here and aren't resource constrained, I'd like to remove this fn in favor of a JSDOM-based solution

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for mentioning this. We will go with the textContent solution.

import _jsdom from 'jsdom'
const {JSDOM} = _jsdom

export {encode, decode} from 'html-entities'
Copy link
Member

Choose a reason for hiding this comment

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

How did we handle these here before adding this module? Does JSDOM handle this for us automatically when we call textContent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point. Looks like JSDOM handles decoding the entities properly for us. I've created a Repl to show the differences between fastGetTrimmedText and JSDOM's textContent.

* Replace JSDOM.fragment calls with ccc-lib's html helper
* Add wrapped cleaning calls to jobs and calendar
* Remove uses of encode/decode
@drewvolz
Copy link
Member Author

Thinking more on this. With this refactoring, I find myself trying to move as much parsing for html, strings, and now data grouping to the backend as possible to lighten the renderer's job.

Would it make sense to create a v2 of ccc-server's calendar and menus APIs to handle the conversion and grouping of events and menus to the client apps? I'm wondering if a v2 of the calendar and menu APIs should be tackled now or later.

@hawkrives
Copy link
Member

I'd be happy with a v2, I suppose. Let's do that in a separate MR, though

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