How to add taxonomies in 11ty? - eleventy

I'd like to use a json-file that looks somewhat like this
[{
"id": "foo",
"url": "video",
"topic": "Fancy foos"},
{
"id": "bars",
"url": "video",
"topic": "Naughty bars"
}]
as a source for several overview pages that group the entries by topic (I guess it's called taxonomy). What would be a good solution for this? Parse the json, group it with js and create a custom collection for each topic? If so, where would this belong, to a file in the _data folder?
Thx in advance!

I'm not 100% sure I get what you intend, but let me try to help. First, yes, store the file in your _data folder. Let's assume you call it taxonomies.json. This means your code has access to the array as taxonomies.
Next, if you want to build pages based on this data, look at the docs for Create Pages from Data, which describe how to dynamically generate pages based on your data. You could have one per taxonomy. For ex:
---
pagination:
data: taxonomies
size: 1
alias: tax
permalink: "topic/{{ tax.id | slug }}/"
---
content here
Your content needs to be driven by the current taxonomy. I assume you will have a kind of content, like posts, that include a taxonomy? If so, you can create a short code or filter that scans all posts and returns the one with a particular taxonomy in the front data. For example, here's how I get posts that match a category:
{% assign posts = collections.posts | getByCategory: cat %}
And getByCategory is defined in .eleventy.js. The particulars of this part are really dependent on what content you are trying to show.

Related

How do I search for logs with values in an array in Datadog?

{
dd {
service cm-api
},
level: INFO,
product_ids: [
4105428,
4105429,
4105430,
4105431,
],
time: 2021-11-20T22:45:11.733088+00:00
}
I want to find all logs that have a certain product_id in them. I want something like (in pseudo-code) #product_ids.contains(4105428). I have tried #product_ids:5845542 but I don't get back logs that have this number in them.
Have you added a Facet to product_ids already? If a field isn't faceted, then it's not readily searchable.
It's usually simplest to view a log entry with the product_ids value and click it, the popup should show "Create facet for product_ids" and then any new logs with that value will be searchable from that point forward.
Read more on Facets: https://docs.datadoghq.com/logs/explorer/facets/
Once it's faceted and searchable, you should be able to use the search syntax you've tried.
More examples: https://docs.datadoghq.com/logs/explorer/search_syntax/#arrays

Change Eve Python DOMAIN collection schema dynamically during runtime

I am using the Eve Python API Framework for MongoDB. I am writing a feature that allows my users to edit metadata sections for the documents that they are writing.
Example JSON:
{
"metadata": {
"document_type": ["story"],
"keywords": ["fantasy", "thriller"]
}
}
We have a CMS for the document editor that admins can use to allow them to do things like add new metadata fields for the authors (normal users) to add more information about their posts. For example, the site admin may want to add a field called "additional_authors" which is a list of strings. If they add this section to the frontend we would like some way to add it to the Eve Schema on the backend in real time without restarting the server. It is very important that it be real time and not part of a coding change in Eve or requiring Eve to restart.
Our current hard-coded metadata schema looks like this for the document collection:
{
"metadata": {
"type": "dict",
"schema": {
"document_type": {"type": "list", "required": True},
"keywords": {"type": "list", "required": True}
}
}
}
I understand that we can go with a non-strict approach when writing the "metadata" type dict so that it does not care what is inside but from my understanding this means we would not be able to use "projection" properly meaning that if I only wanted to return "metadata.additional_authors" of all documents through my API call, I would not be able to do so. Also, this would mean that we would have to deal with the required check ourselves using hooks instead of the built-in Eve schema check.
Is there anyway around this issue by essentially having a dynamic schema based on a MongoDB document that we can store the entire collection configuration dict in and retrieve it without restarting the server for it to take effect? Even if this means adding a hook to the new schema_dict collection and calling some internal Eve function I am all ears.
Thank you ahead of time for your help.

Add a tag to an existing contact using the Mautic API

I've been driving myself crazy for days trying to figure it out.
When I search "tags" in the docs, the only results seem to relate to creating and editing the tag records themselves rather than any association to a contact's record.
I see this test class linked from this issue but don't understand since there isn't actual documentation or a simple example of how to use the API to add a tag to a contact.
I'd appreciate any help. Thanks.
'tags' => ['tag1', 'tag2']
P.S. That test class code seems to be for creating a new contact with certain tags, when instead what I want to do is associate an existing tag with an existing contact.
It's the same payload for create and update as well.
Endpoint: PATCH api/contacts/ID/edit
With data: tags[0]=tagA
which will URL decode to: tags%5B0%5D=tagA
Or you can use JSON format for the data payload if you specify it in the header ('Content-Type: application/json'):
{
"tags": ["tagA"]
}
The request is containing the tag like this:
{
"contact": {
...
"tags": [
{
"id": 32,
"tag": "tagA"
}
],
...
}

Alchemy CMS: Create element that contains list of elements

I'd like to create an element which can contain a list of items, where each item can have more than one essences.
For example:
The user should be able to add a "page listing" as content element. For each page item he should be able to upload a small image, a short description and a link. Because the list needs to be wrapped with an UL tag, I can't simply ask him to add a lot of elements.
Other example:
The user should be able to add a "team listing" as content element. Each member having a photo, a name, a job description and an email address. Same problem here: I'd like to have the team members wrapped within an DL tag.
Is there some way of releasing elements which can contain elements?
Some kind like: (just an example, might contain bugs)
- name: my_list_element
contents:
- name: list_style
type: EssenceSelect
- name: items
type: Element ???
elements: [my_item_element]
settings:
deletable: true
available_contents:
- name: items
type: Element ???
elements: [my_item_element]
settings:
deletable: true
- name: my_item_element
contents:
- name: image
type: EssencePicture
- name: headline
type: EssenceText
...
The inner item uses the default editor for pictures or text essences.
If someone knows a way how to realize this it would be very great, because it's the last puzzle part which is missing in order to use alchemy CMS :(
Thank you in advance
You want to use the new nestable Elements feature you'll find in the current master and soon to be released 3.3 version. Unfortunately they are not well documented yet. Sorry.
But it's really simple. Instead of the available_contents (That will be deprecated in favor of nested elements anyway, you list names of nestable_elements).
A nestable element can be any element you have defined.
Unless the guides got updated, please read the documentation in the code.
You may use http://ruby-doc.org/stdlib-2.1.0/libdoc/yaml/rdoc/YAML.html and get Hash in the output and also save it in text as well
Hope to see nestable_elements feature soon, may be it will solve some really obvious tasks. For now, without the possibility to easy extend Alchemy with custom models (Post, TeamMember, Testimonial, PortfolioItem, etc) I am still the fan on RefineryCMS or pure RoR, and this is sad, because AlchemyCMS has really nice things built-in.
As I can understand, this feature will be implemented in Alchemy 4 by Nodes, even the Page model will be registered as Alchemy::Node, and developer will be able to create own Nodes which will behave like custom_post_type in WordPress.

How can I populate a jQuery template (tmpl) using HTML5 Local Storage data

I am trying to build a simple jQuery UI template and populate it with data stored in the localStorage.
I need to set the local storage with a list of guests and have the user edit the list. When clicking update, the changes are sent back to the server.
<ul id="guests">
<li>
Name: ${name} <br />
Phone: ${phone} <br />
Email: ${email}
</li>
</ul>
I am really new at this and have no idea what to do. I am just interested in setting the local storage when the page loads and populating the template.
Can someone please provide a short tutorial?
I thought this is a simple question... Can someone please let me know in case it is not possible at all? Thanks!
you say you want to save the data to localStorage, but also that you want to send modified data to the server.
I would suggest that you divide this problem up into (Part 1) learning how to save locally to localStorage and rendering that content with templating and then (Part 2) learning how to store on a server. I can help you with Part 1, since quite frankly I'm still learning about Part 2 myself.
Okay so, two subtasks:
using localStorage to persist data
using jQuery templates to render data
Using localStorage
You haven't specified where your data is coming from, so I'll assume you have some JSON. For simplicity I'll just use this data:
(You might be wondering why I added content that isn't plain ASCII -- it's just a habit of mine, I believe in testing with realistic text from the get-go. When we finally render this data, it should look right in your browser.)
var philosophers = [
{
"phone": "1-800-123-1937",
"name": "H\u00e9l\u00e8ne Cixous",
"email": "helene#stanford.edu"
},
{
"phone": "1-800-000-0000",
"name": "\u041c\u0438\u0445\u0430\u0438\u0301\u043b \u0411\u0430\u043a\u0443\u0301\u043d\u0438\u043d",
"email": "mikhail#ispitondns.com"
},
{
"phone": "1-800-770-0830",
"name": "Jayar\u0101\u015bi Bha\u1e6d\u1e6da",
"email": "jay#ancientindia.edu"
}
]
So we need to get this into localStorage, just to have some data to start with.
The trick about localStorage is that you can't just directly store JSON objects. You can only store strings. There are some libraries out there designed to improve on this situation, but we'll just convert our objects ourselves. To do that we'll use JSON:
localStorage.philosophers = JSON.stringify(philosophers)
Unsurprisingly, JSON.stringify turns JSON objects into a string, and that can be set directly as an "attribute" of localStorage.
(If you're using an old browser, then you might not have the native JSON object -- there's a library you can include for that too.)
Okay, so now we have some contact data stashed in localStorage with the label of philosophers. (Hey, you never know when you might need to call a philosopher!)
To get that data back out and into a Javascript object we can do something with, we use another JSON method, JSON.parse.
philosophers = JSON.parse(localStorage.philosophers)
This is all pretty artificial, since we've got the philosophers data in the first place, then we stringify it, and then we store it, and then we take it right back out, and then we parse it, and then we're back where we started. But in reality such data will come from some other source -- perhaps an external file or a web service or whatever.
Using templates to render objects
Since you used what looks like jQuery template syntax in your template, I'm going to assume that's the library you're using. The jQuery docs show us how we can render a variable containing some objects (like what we have in our philosophers variable) with a template, here's the key bit of those docs:
// Convert the markup string into a named template
$.template( "summaryTemplate", "<li>${Name}</li>" );
function renderList() {
// Render the movies data using the named template: "summaryTemplate"
$.tmpl( "summaryTemplate", movies ).appendTo( "#moviesList" );
}
Here's one way you can get your template to work (there are other, arguably cleaner methods, but jQuery templates are a topic unto themselves):
var myTemplate = "<li>Name: ${name}<br/>Phone: ${phone}<br/>Email: ${email}</li>";
$.template("contactLi", myTemplate);
That creates a template and stores it in a variable named contentLi. (Note that $.template wants that given variable name given as a string, which strikes me as weird. I find the way jQuery templates names and defines these methods confusing, which is one of the reasons I prefer Mustache for templating. Shrug.)
Also, note that we don't have the ul included in the template, because that's not going to be repeated for each rendered object. Rather, we're going to add the ul as a hook in the markup, and render the assembled template repeatedly as a child of that. Which just takes a single line with jQuery templates, rather nice:
$.tmpl( "contactLi", philosophers ).appendTo( "#guests" );
So there you go, a rendered list.
I know this doesn't answer your whole question but there's a lot here to start with.
Here's an example you can try out, it ends up rendering something like:
Name: Hélène Cixous
Phone: 1-800-123-1937
Email: helene#stanford.edu
Name: Михаи́л Баку́нин
Phone: 1-800-000-0000
Email: mikhail#ispitondns.com
Name: Jayarāśi Bhaṭṭa
Phone: 1-800-770-0830
Email: jay#ancientindia.edu
(Hehe, boy, SO's syntax highlighting doesn't handle that Unicode text very well!)
try AmplifyJS -- can extract your data as json the same way you would as $.getJSON

Resources