export function getDocuments<T>(slug: ''): Promise<T[]>;
export function getDocuments<T>(slug: string): Promise<T>;
export function getDocuments<T>(): Promise<T[]>;
export function getDocuments(slug = ''): Promise<unknown> {
const endpoint = `/documents/${slug}`
return getPosts(endpoint);
}
const WorkQuery = graphql`
query WP_Posts {
allWpPost {
edges {
post: node {
id
title
slug
excerpt
uri
}
}
}
}
}
`
const Work = () => {
const query = useStaticQuery()
return (
{query.allWpPost.edges.map(({ post }) => (
<div>
<Link to={post.slug}>
<p>{post.title}</p>
</Link>
<div dangerouslySetInnerHTML={{ __html: post.excerpt }} />
</div>
))}
)
}
export default Work
- export const WorkQuery = graphql`
query WP_Posts {
allWpPost {
edges {
post: node {
id
title
slug
excerpt
uri
}
}
}
}
}
`
-
+ export const query = graphql`
query WP_Posts {
allWpPost {
edges {
post: node {
id
title
slug
excerpt
uri
}
}
}
}
}
`
from itertools import groupby
test_list = [{'group': 'style', 'name': 'Классика'}, {'group': 'style', 'name': 'Модерн'}, {'group': 'type', 'name': '2-х комнатная квартира'}, {'group': 'style', 'name': 'Модерн'}]
keyfunc = lambda x:x['group']
res = [list(data) for _, data in groupby(sorted(test_list, key=keyfunc), key=keyfunc)]
from itertools import groupby
from operator import itemgetter
data = [
{'group': 'style', 'name': 'Классика'},
{'group': 'style', 'name': 'Модерн'},
{'group': 'type', 'name': '2-х комнатная квартира'}
]
ig = itemgetter('group')
result = [list(group) for key, group in groupby(sorted(data, key=ig), ig)]
from collections import defaultdict
data = [
{'group': 'style', 'name': 'Классика'},
{'group': 'style', 'name': 'Модерн'},
{'group': 'type', 'name': '2-х комнатная квартира'}
]
result = defaultdict(list)
for item in data:
result[item['group']].append(item)
result = list(result.values())
.py
:dev.config.py # в .gitignore
test.config.py # в .gitignore
config.py # болванка
.env
, то можно делать аналогично:dev.env
prod.env