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