Get the first page header 1 through a query

I use named file with the date
For the links I would need to get the text from the first header

Example:
filename: 2024-02-21 23:17:34
content:
# This is the first header 1
This is text…

My query:
```query
page select name, first-header1?? order by lastModified desc limit 10
```

Is it possible to get this value from the query? or otherwise?
The reason is that I want to use this text to put in the link instead of the file name.

Very thanks. :slightly_smiling_face:

If i understood you correctly, one way to achieve what you need is like this:

  1. Create a template, example Library/Personal/Query/header.md
    (you can place that file wherever you want, this is just my convention)
---
tags: template
---

* [[{{page}}|{{name}}]]
  1. If you want to search for all files with that format, you can use the following regex to find them /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/
    Info on how to search for headers here: Objects

Then the query would be:

header select page,name where page =~ /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/ and level = 1 render [[Library/Personal/Query/header]]

Let me know if this is what you were looking for

1 Like


Sorry, I didn’t explain myself well.

What I’m looking for is for the link to display the text of the first header 1 of the page.

Example:
filename: 2024-02-21 23:17:34
content:

This is the first header 1

This is text…

The result I’m looking for is the following:
[[2024-02-21 23:17:34|This is the first header 1]]

The page does not have a yaml title
This is why I try to show the first header page for make links.
Is possible?

Very thanks.

I am not sure I understand you correctly.

If what you want is [[2024-02-21 23:17:34|This is the first header 1]], that is exactly what I showed you in my answer.

Let me make a real example:

I just created this quick note:

A quick note for today

# Helping Dani

Let’s try and see if I can help Dani with this topic

## Solution

Here goes the solution

If I now use the query I posted, I see the following:

And clicking there, I go to the page Inbox/2024-02-22 12:10:28

I’ll try to get what I’m looking for.
This does not have the lastModified date so it cannot sort.
I think I know how to get it.
Once I get it I will put the answer here.
Thank you very much.

That’s a simple addition

```query
header select page,name where page =~ /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/ and level = 1 order by lastModified desc render [[Library/Personal/Query/header]]
```

Very thanks. :slightly_smiling_face:

I made it.

Sure it can be done better but this works.
If a page has no yaml title but has h1, use the value of h1 as title («titulo»).

This is de code

```template
 {{#each @p in {page where name !=~ /^Library\//  and name != 'index' and name != 'SETTINGS' and name != 'STYLES' order by lastModified desc limit 10}}}
{{#if @p.titulo}}
* [[{{@p.name}}|{{@p.titulo}}]]
{{else}}
{{{header where [email protected] and level = 1 limit 1 select page,name   render[[Library/Personal/Templates/ligazon-h1]]}}}
{{/if}}
{{/each}}
```

ligazon-h1 file:

* [[{{page}}|{{name}}]]
1 Like

Enhorabuena, bien hecho! :muscle:

With this:

If the page, for example, has 3 headings 1 and we want the first one to appear, the following corrections must be made (add “order by line”):

{{{header where [email protected] and level = 1 limit 1 
select page,name, line order by line  render[[Library/Personal/Modelos/Ligazon-h1]]}}}
1 Like