Use Eleventy 11ty Nested Data to Generate Pages - collections

I have a nested local data object (locale.json). And would like to use it to generate child folders and pages.
Folder structure
src/
locale/
locale.json
locale.json
{
"currency": "USD",
"language": "en-US",
"groups": [
{
"name": "Group A",
"types": [
{
"name": "Type 1",
"members": [
{
"id": "ABCD1234567890"
},
{
"id": "EFGH0987654321"
}
]
}
]
}
]
}
I would like to generate 1 page per member in their group for each locale.
Example: /en-US/group-a/ABCD1234567890.html
dist/
en-US/
group-a/
ABCD1234567890.html
But, I haven't found a way to use 11ty pagination or collections to make it happen.
I'm new to 11ty data and would appreciate your help.
Thanks!

Related

Omitting Weaviate Objects Containing Specific Reference

Suppose I have a database of movies with some genres tagged to it. My Weaviate schema looks like this:
"classes": [{
"class": "Movie",
"properties": [{
"name": "name",
"dataType": ["string"],
}, {
"name": "inGenres",
"dataType": ["Genre"],
}],
}, {
"class": "Genre",
"properties": [{
"name": "name",
"dataType": ["string"],
}],
}]
I would like to exclude movies tagged with a specific genre from the search results. Specifically, for a database containing the following Movie objects:
{"name":"foo", "inGenres":[{"name":"drama"}]}
{"name":"bar", "inGenres":[{"name":"horror"},{"name":"thriller"}]}
{"name":"baz", "inGenres":[{"name":"horror"},{"name":"sci-fi"}]}
If I exclude the horror genre, the search results should only return the movie foo. Is there any way to perform such a query with GraphQL or the Python client?
You can use the where filter to achieve this.
In your specific case:
{
Get {
Article(
where: {
path: ["inGenres", "Genre", "name"],
operator: NotEqual,
valueString: "horror"
}
) {
name
inGenres {
... on Genre {
name
}
}
}
}
}
In Python
import weaviate
client = weaviate.Client("http://localhost:8080")
where_filter = {
"path": ["inGenres", "Genre", "name"],
"operator": "NotEqual",
"valueString": "horror"
}
query_result = client.query.get("Movie", ["name"]).with_where(where_filter).do()
print(query_result)

CosmosDB SQL to query "any" child field

Given a document structure like below, where "variants" has N id based sub-entries, I would like to filter on the inner "sku" field. Something akin to this:
SELECT * FROM c WHERE c.variants.?.sku = "some_sku_1"
Here "some_id_1" and "some_id_2" are id values, data driven, and cannot be part of the query.
Is this possible with Cosmos DB and if so, how?
{
"id": "45144",
"variants": {
"some_id_1": {
"sku": "some_sku_1",
"title": "some title 1"
},
"some_id_2": {
"sku": "some_sku_2",
"title": "some title 2"
}
}
}
You can't do that with that schema without using a UDF/SPROC, but if you change the schema slightly, you can do it.
Schema:
{
"id": "45144",
"variants": [
{
"id": "some_id_1",
"sku": "some_sku_1",
"title": "some title 1"
},
{
"id": "some_id_2"
"sku": "some_sku_2",
"title": "some title 2"
}
]
}
Query:
SELECT * FROM c IN Item.variants WHERE c.sku == "some_sku_1"
Check out this article to get a good idea of what's possible with that "IN' statement, which allows you to iterate over objects. https://learn.microsoft.com/en-us/azure/cosmos-db/sql-api-sql-query#Advanced

How to associate nested relationships with attributes for a POST in JSON API

According to the spec, resource identifier objects do not hold attributes.
I want to do a POST to create a new resource which includes other nested resource.
These are the basic resources: club (with name) and many positions (type). Think a football club with positions like goalkeeper, goalkeeper, striker, striker, etc.
When I do this association, I want to set some attributes like is the position required for this particular team. For example I only need 1 goalkeeper but I want to have a team with many reserve goalkeepers. When I model these entities in the DB I'll set the required attribute in a linkage table.
This is not compliant with JSON API:
{
"data": {
"type": "club",
"attributes": {
"name": "Backyard Football Club"
},
"relationships": {
"positions": {
"data": [{
"id": "1",
"type": "position",
"attributes": {
"required": "true"
}
}, {
"id": "1",
"type": "position",
"attributes": {
"required": "false"
}
}
]
}
}
}
}
This is also not valid:
{
"data": {
"type": "club",
"attributes": {
"name": "Backyard Football Club",
"positions": [{
"position_id": "1",
"required": "true"
},
{
"position_id": "1",
"required": "false"
}]
}
}
}
So how is the best way to approach this association?
The best approach here will be to create a separate resource for club_position
Creating a club will return a url to a create club_positions, you will then post club_positions to that url with a relationship identifier to the position and club resource.
Added benefit to this is that club_positions creation can be parallelized.

How to create multiple tabs of forms using angular json schema form?

I have been successfully using this awesome library and concept called json schema form.
https://www.npmjs.com/package/angular2-json-schema-form
Now using the schema patterns given I am able to generate a form based on a dynamically created schema from database. I want to convert the single form in multiple tabs. I.E I want to group certain kind of fields in one panel.
Is there any kind of support for this functionality? So that I can assign the css class according to the layout.
https://angular2-json-schema-form.firebaseapp.com/?set=ng-jsf&example=ng-jsf-flex-layout&framework=material-design&language=en
You can split group of fields into separate tabs using the fieldsets property.
See the following example from README.md:
{
"properties": {
"firstName": {
"type": "string",
"description": "First name"
},
"lastName": {
"type": "string",
"description": "Last name"
},
"email": {
"type": "string",
"description": "Email"
},
"notificationsFrequency": {
"type": "string",
"description": "Notifications frequency",
"widget": "select",
"oneOf": [
{
"description": "Daily",
"enum": [
"daily"
]
},
{
"description": "Weekly",
"enum": [
"weekly"
]
},
{
"description": "Monthly",
"enum": [
"monthly"
]
}
],
"default": "daily"
}
},
"fieldsets": [
{
"title": "Personal information",
"fields": [
"firstName",
"lastName",
"email"
]
},
{
"title": "Account settings",
"fields": [
"notificationsFrequency"
]
}
]
}

Firebase data structure/indexes for folder system

I have the following data structure:
"users": {
$userid: {
"forms": {
"ID_OF_FORM 1": { "name": "Name goes here" },
"ID_OF_FORM 2": { "name": "Name goes here" }
}
}
}
I want to be able to put my "forms" in a folder system to better organize all of them for the user. Right now I call them using /users/auth.id/forms/ID. I was planning on putting objects inside the forms object but I don't think i'll be able to call them with just the form id anymore if I do that.
I can't wrap my head around how I should store these folders so that they can easily be displayed.
I need to display all the folders inside root or the active id of
a folder that a user is currently in.
I also need to be able to call a form using the id of the form
Do you think this would work? Does anyone have any better suggestions on going about doing this?
"users": {
$userid: {
"forms": {
"ID_OF_FORM 1": { "name": "Name goes here", "folder_id": "ID_OF_FOLDER" },
"ID_OF_FORM 2": { "name": "Name goes here", "folder_id": "ID_OF_FOLDER" }
},
"folders": {
"ID_OF_FOLDER 1": { "name": "name of folder" },
"ID_OF_FOLDER 2": { "name": "name of folder" },
"ID_OF_FOLDER 3": {
"name": "name of folder",
"ID_OF_FOLDER 4": { "name": "would this even work" }
}
}
}
}
Looks fine to me, although it is difficult to be certain unless one knows all use-cases (for which StackOverflow is not really the right forum).
I would change the folders a bit into:
"folders": {
"ID_OF_FOLDER 1": { "name": "name of folder" },
"ID_OF_FOLDER 2": { "name": "name of folder" },
"ID_OF_FOLDER 3": { "name": "name of folder" },
"ID_OF_FOLDER 4": { "name": "would this even work", "folder_id": "ID_OF_FOLDER 3" }
}
Otherwise you run the risk of going over the 32 level limit that Firebase imposes on the depth of the tree. The nice thing is that you can directly access any folder by its ID here.
You may consider using a single top-level node for all item types, both forms and folders (and anything else that might come along as you're building the application):
"items": {
"ID_OF_FORM 1": { "type": "form", "name": "Name goes here", "folder_id": "ID_OF_FOLDER" },
"ID_OF_FORM 2": { "type": "form", "name": "Name goes here", "folder_id": "ID_OF_FOLDER" }
"ID_OF_FOLDER 1": { "type": "folder", "name": "name of folder" },
"ID_OF_FOLDER 2": { "type": "folder", "name": "name of folder" },
"ID_OF_FOLDER 3": { "type": "folder", "name": "name of folder" },
"ID_OF_FOLDER 4": { "type": "folder", "name": "would this even work", "folder_id": "ID_OF_FOLDER 3" }
}
But I don't think this is too beneficial for your use-case at the moment. Given what you've said, the split between folders and forms seem pretty good.

Resources