Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
astro-wt
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
1367a306
authored
2024-11-27 08:32:16 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Move createAdjuster from external to html.
1 parent
0d873159
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
lib/external.astro
lib/html.ts
lib/external.astro
View file @
1367a30
---
import { parseHtml, createMatcher, findNode } from './html.ts'
import { parseHtml, create
Adjuster, create
Matcher, findNode } from './html.ts'
import { getUrl, getSitePage } from './remote-content.ts'
import Match from './match.astro'
...
...
@@ -24,19 +24,6 @@ export const getNodesFromProps = async (props, options) => {
return xpath ? findNode(doc, xpath, { single: false }) : [ doc ]
}
export const createAdjuster = (adjustments = {}) => {
const adjustmentsCompiled = Object.entries(adjustments).map(([ selector, handler ]) => [ createMatcher(selector), handler ])
const adjuster = (node, parent, index) => {
for (const [ matcher, handler ] of adjustmentsCompiled) {
if (matcher(node, parent, index, false)) {
node = handler(node)
}
}
return node
}
return adjuster
}
const { props } = Astro
const { debug, replacers, slotHandler } = props
const nodes = await getNodesFromProps(props)
...
...
lib/html.ts
View file @
1367a30
...
...
@@ -343,6 +343,19 @@ export const createMatcher = (selector: string): Matcher => {
return
newMatcherCreater
()
}
export
const
createAdjuster
=
(
adjustments
=
{})
=>
{
const
adjustmentsCompiled
=
Object
.
entries
(
adjustments
).
map
(([
selector
,
handler
])
=>
[
createMatcher
(
selector
),
handler
])
const
adjuster
=
(
node
,
parent
,
index
)
=>
{
for
(
const
[
matcher
,
handler
]
of
adjustmentsCompiled
)
{
if
(
matcher
(
node
,
parent
,
index
,
false
))
{
node
=
handler
(
node
)
}
}
return
node
}
return
adjuster
}
const
reactAttributeMap
=
{
'class'
:
'className'
,
'srcset'
:
'srcSet'
,
...
...
Please
register
or
sign in
to post a comment