mirror of
https://github.com/Afilmory/afilmory
synced 2026-02-01 22:48:17 +00:00
- Refactored the database connection logic to utilize `neondatabase`, ensuring correct imports and type safety. - Implemented atomic upsert operations in the views API, allowing for efficient insertion and updating of records using PostgreSQL's `ON CONFLICT` clause. - Added new dependencies `ast-kit` and `unplugin-ast` for improved AST manipulation in the project. - Enhanced the UI components with toast notifications for user feedback on reactions and improved styling with Tailwind CSS. Signed-off-by: Innei <tukon479@gmail.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { isTaggedFunctionCallOf } from 'ast-kit'
|
|
import type { Transformer } from 'unplugin-ast'
|
|
import AST from 'unplugin-ast/vite'
|
|
|
|
// Custom transformer for tw function that compresses template strings
|
|
const TwTransformer: Transformer<any> = {
|
|
onNode: (node) => isTaggedFunctionCallOf(node, ['tw']),
|
|
transform(node) {
|
|
if (node.type === 'TaggedTemplateExpression') {
|
|
const { quasi } = node
|
|
|
|
// Process template literals
|
|
if (quasi.type === 'TemplateLiteral') {
|
|
// Get the raw string content
|
|
const rawString = quasi.quasis[0]?.value?.raw || ''
|
|
|
|
// Compress the string: remove extra whitespace, newlines, and normalize spaces
|
|
const compressedString = rawString
|
|
.replaceAll(/\s+/g, ' ') // Replace multiple whitespace with single space
|
|
.trim() // Remove leading and trailing whitespace
|
|
|
|
// Update the template literal
|
|
quasi.quasis[0].value.raw = compressedString
|
|
quasi.quasis[0].value.cooked = compressedString
|
|
}
|
|
|
|
return quasi
|
|
}
|
|
return node.arguments[0]
|
|
},
|
|
}
|
|
|
|
export const astPlugin = AST({
|
|
transformer: [TwTransformer],
|
|
})
|