CodeWindow reference
Below is an example of a CodeWindow
block.
function hello(name, options) {
if (a) {
return false
}
const greeting = "hi, " + name
console.log(greeting)
return true
}
The LitCodeWindow
element allows for code to be interspersed with text.
import 'react' from React
import 'react-dom' from ReactDOM
it('works', () => {
ReactDOM.render(<div>hello!</div>, document.body)
expect(document.body.innerText).toBe('hello!')
JSX support — JSX fragments like these often need Babel to be integrated with Jest. This just works with Vitest.
})
export async function getStaticPaths() {
const posts = await Astro.glob('../content/posts/**/*.md');
return posts.map(
({ Content, file, frontmatter }) => {
const slug = file.split('/').at(-2);
const { title } = frontmatter
return {
params: { slug },
props: { Content, title },
};
},
);
This fetches using
Astro.glob()
.Content
is an Astro component that will be passed on as props.
const { title, Content } = Astro.props
---
<BaseLayout>
{title}
<Content />
</BaseLayout>
The component will be rendered here.
const node = document.createElement('div')
document.body.appendChild(node)
document.getElementById('node')
This returns a single node.
def index
@page = params[:page].to_i
@articles = Article.page(@page)
end
NoMethodError (undefined method
to_i
for["1"]:Array
)
Did you mean?to_s