Content.utils.ts 1.1 KB

123456789101112131415161718192021222324252627
  1. export const navigateToSection = (key: string) => {
  2. if (typeof window !== 'undefined') {
  3. const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
  4. const el = document.getElementById(key)
  5. if (el) {
  6. el.scrollIntoView({ behavior: prefersReducedMotion ? 'instant' : 'smooth' })
  7. // Timeout needed to make sure the focus behavior doesn't interrupt the
  8. // scrolling. Timing selected by trial and error.
  9. setTimeout(() => el.focus(), 300)
  10. }
  11. }
  12. }
  13. // Removes some auto-generated Postgrest text
  14. // Ideally PostgREST wouldn't add this if there is already a comment
  15. export const tempRemovePostgrestText = (content: string) => {
  16. const postgrestTextPk = `Note:\nThis is a Primary Key.<pk/>`
  17. const postgrestTextFk = `Note:\nThis is a Foreign Key to`
  18. const pkTextPos = content.lastIndexOf(postgrestTextPk)
  19. const fkTextPos = content.lastIndexOf(postgrestTextFk)
  20. let cleansed = content
  21. if (pkTextPos >= 0) cleansed = cleansed.substring(0, pkTextPos)
  22. if (fkTextPos >= 0) cleansed = cleansed.substring(0, fkTextPos)
  23. return cleansed
  24. }