### Tags:
#RogueHistory/Notes #Obsidian/Notes #Obsidian/Dataview
---
# What I was trying to do
The goal is to create a query that fetches the ten most recently updated files and the ten recently created notes and have these published on the Welcome pages of [[01 Rogue History Notes]].
## challenges
The challenge for this task is that dataview is a community developed plugin by Michael Brenan [blacksmithgu/obsidian-dataview.](https://github.com/blacksmithgu/obsidian-dataview). Obsidian Publish does not support community developed plugins and will only render the dataview query code and not the HTML for the code. Thus, any query using dataview in a note will not be rendered into HTML and is unreadable on an Obisdian Publish site.
## what I did
- step 1 Consulted Gemini 2.5 Pro
- Results: Were poor. I knew the dataview plugin did not work with Publish, but I was optimistic that Gemini could provide a code workaround. It did not. It did not recognize that the dataview plugin was not compatible with publish and provided code that did not work. I prompted Gemini that the dataview plugin was not compatible and it still did not provide a viable solution. See [[#Prompts and Responses]] for prompts and responses. Of particular interest, I noted in the system instructions that Gemini is an Expert in Obsidian and Obsidian Publish and it still did not identify that dataview was not renderable in Publish.
- step 2 Searched YouTube.
- Results: YouTube is my go to for all matters Obsidian and I can usually find an answer or sources that lead to solutions. Here I found a website and video by Josh Plunkett [TTRPG Tutorials](https://obsidianttrpgtutorials.com/Obsidian+TTRPG+Tutorials/Plugin+Tutorials/Dataview/Dataview+-+Obsidian+Publish), [Obsidian Publish with Dataview ](https://www.youtube.com/watch?v=c440B2aOPJ8&t=1s), who uses a modified solution from [joschua.io](https://joschua.io/posts/2023/09/01/obsidian-publish-dataview) The code provided solved my problem and provided a reasonable explanation for how the code operates. See [[#Code]] below.
- step 3 Modified and executed code.
- Results: The code executed as desired and I now have my most recently created and updated files published on the RHN Welcome page. However each time I execute the code it creates an [untitled] note, which I do not understand at this time.
1. First make sure you have the necessary plugins. Templater and Dataview which can be found via Github at [Templater: A template plugin for obsidian](https://github.com/SilentVoid13/Templater) and [obsidian-dataview](https://github.com/blacksmithgu/obsidian-dataview) or under community plugins in your Obsidian Settings. See [Templater Plugin for Research Notes — Rogue History](https://www.roguehistory.ca/rh-notes/adding-plugins) for a guide on installing the templater plugin, which is usable for dataview.
2. Copy code from either source noted above and create a new note in your Obsidian Vault, wherever you store your templates. I named mine [[17.31 New_Updated_Notes]]. Paste the code into the note and create a hotkey to execute the note. [ control + U] is what I use.
3. Ensure that the new notes are all published in your Obsidian Publish or they will not render.
4. You can put the new notes, i.e, [[17.32 New files]], [[17.33 Recently edited]], into your desired folder.
5. When the template is executed, the code updates the query, renders it into a markdown table, which Obsidian Publish can read and render into HTML format.
## Code:
```
<%*
const dv = app.plugins.plugins["dataview"].api;
const openPublishPanel = app.commands.commands["publish:view-changes"].callback;
// Add as many filenames and queries as you'd like!
const fileAndQuery = new Map([
[
"Recently edited",
'TABLE WITHOUT ID file.link AS Note, dateformat(file.mtime, "ff") AS Modified FROM "Obsidian TTRPG Tutorials" AND -#Ignore WHERE publish = true SORT file.mtime desc LIMIT 7',
],
[
"Player List",
'TABLE WITHOUT ID link(file.name) AS "Character Name", Player, Class, Race, level, Role from "1. The Party/Deadly Depth Inn" where (Role = "Player") where (Status = "Active")',
],
[
"Recent new files",
'TABLE WITHOUT ID file.link AS Note, dateformat(file.ctime, "DD") AS Added FROM "Obsidian TTRPG Tutorials" AND -#Ignore WHERE publish = true SORT file.ctime desc LIMIT 7',
],
]);
await fileAndQuery.forEach(async (query, filename) => {
if (!tp.file.find_tfile(filename)) {
await tp.file.create_new("", filename);
new Notice(`Created ${filename}.`);
}
const tFile = tp.file.find_tfile(filename);
const queryOutput = await dv.queryMarkdown(query);
const fileContent = `%% #Ignore update via "Update Publish Files" template %% \n\n${queryOutput.value}`;
try {
await app.vault.modify(tFile, fileContent);
new Notice(`Updated ${tFile.basename}.`);
} catch (error) {
new Notice("⚠️ ERROR updating! Check console. Skipped file: " + filename , 0);
}
});
openPublishPanel();
%>
```
## thoughts on where to go next
Next is to add columns to the table with additional information on the notes. For example, Status = Complete, Project = PhD project, or Priority = High, so on a nd so forth, and to fix the [untitled] note creation.
---
## Prompts and Responses
#### **System Instructions**
`You are an expert on Obsidian.md and Obsidian Publish. Your expertise in these programs is in customizing an Obsidian webpage. `
#### **My Prompt**
>[! Prompt]
>I have an Obsidian Publish site at https://publish.obsidian.md/roguenotes/00+Welcome/01+Rogue+History+Notes and want a code that will publish the three most recently created notes to the welcome page under the heading New Notes. Is this possible?
#### **Gemini 2.5 Pro**
>[! Danger] Response
>Of course. As an expert in Obsidian.md and Obsidian Publish, I can guide you on how to dynamically display your most recently created notes on your welcome page.
>
>Yes, this is possible. The most effective way to achieve this is by using a combination of the Obsidian Dataview plugin and custom CSS to style the results on your Obsidian Publish site.
>
>### Displaying Recently Created Notes on Obsidian Publish
>
>Here is the code and the steps required to get this feature working on your site. This solution will automatically generate a list of the three most recently created notes that have been published.
>
>#### 1. The Dataview Query
>
>First, you need to have the [Dataview plugin](https://blacksmithgu.github.io/obsidian-dataview/) installed in your local Obsidian vault. Then, on the page where you want the list to appear (your "00 Welcome" note), place the following Dataview query block:
>
>```dataview
TABLE WITHOUT ID
file.link AS "Note Title",
file.cday AS "Date Created"
FROM ""
WHERE file.cday
SORT file.cday DESC
LIMIT 3
> [! Danger] Response Cont...
> **How this query works:**
> * `TABLE WITHOUT ID`: This creates a table without the default first column showing the file path.
> * `file.link AS "Note Title"`: This displays the note's title as a clickable link.
> * `file.cday AS "Date Created"`: This displays the creation date of the file.
> * `FROM ""`: This tells Dataview to search all notes in your vault.
> * `WHERE file.cday`: This ensures that only notes with a creation date are included.
> * `SORT file.cday DESC`: This is the key part that sorts all your notes by their creation date in descending order (newest first).
> * `LIMIT 3`: This restricts the output to only the top three results.
>
> ### 2 Publishing Your Notes
> For the list to populate correctly on your Obsidian Publish site, you must ensure two things:
> * The welcome note containing the Dataview query is published.
> * The notes that you expect to see in the list are also published. The query can only see notes that exist on your Publish site.
>
> ### 3 (Optional) Customizing the Appearance with CSS
> By default, the output will look like a standard table. If you'd like to make it a cleaner list, you can add custom CSS to your Obsidian Publish site.
> 1. In Obsidian, go to `Settings` > `Appearance` and scroll down to the `CSS snippets` section.
> 2. Create a new CSS file in the `.obsidian/snippets` folder of your vault (e.g., `publish-styles.css`)
> 3. Add the following CSS to that file:
```css
/* Hide the header on your recent notes list */
.dataview-table-header {
display: none;
}
/* Style the links to look more like a simple list */
.dataview-result-list-root-ul {
list-style-type: none;
padding-left: 0;
}
```
> [! Danger] Response Cont...
> 4. Upload this `publish-styles.css` file to your Obsidian Publish site via the "Publish changes" dialog. Make sure to enable it after uploading.
>
> This will hide the "Note Title" and "Date Created" headers and present your recent notes as a clean, simple list of links.
#### **My Prompt**
> `The query is not working on the published site. I have ensured all notes are published as well as the Welcome page. What appears to be the problem? Here is the dataview query used in the note along with a screenshot of what is published.
`md``dataview
TABLE WITHOUT ID
file.link AS "Note Title",
file.cday AS "Date Created"
FROM ""
WHERE file.cday
SORT file.cday DESC
LIMIT 3
![Image]
#### ** Gemini Response**
>[! Danger] Response
>Of course. As an expert on Obsidian.md and Obsidian Publish, I can help you with this.
>
>Thank you for providing the screenshot. It shows the exact problem, which is a common point of confusion when first using plugins with Obsidian Publish.
>
>The reason you are seeing the raw code block instead of the list of notes is that **Obsidian Publish does not run the Dataview plugin on the server**. Instead, your local Obsidian application is supposed to *render* the query into a static HTML table *before* it gets sent to your Publish site.
>
>Your screenshot confirms that this rendering step is not happening. This is almost always caused by a security setting within the Dataview plugin itself being disabled.
>
>### The Solution: Enable Dataview Execution Settings
>
>To fix this, you need to enable the settings that allow Dataview to execute and generate the table in your vault.
>1. In your Obsidian app, go to **Settings**
>2. On the left-hand menu, scroll down to the "Community plugins" section and click on **Dataview**. This will open the Dataview plugin settings
>3. Scroll down to the **"Security"** section
>4. Make sure that **`Enable JavaScript Queries`** and **`Enable Inline JavaScript Queries`** are both toggled **ON**, as shown below.
>
> **Close the settings panel.**
>
> ### Final Step: Republish the Note
>
> Now that you've changed the setting, you must tell Obsidian to re-process and republish the note.
> 1. Open the "Publish changes" dialog.
> 2. Find your welcome note in the list of changed files (it may not show up automatically, in which case you can select it from the list of all published notes)
> 3. Select it and click **Publish**.
>
> Once the site has updated, the page should now show the rendered list of your three most recent notes instead of the code block.
> ***
> #### **Why does this work?**
> By default, these settings are sometimes turned off for security reasons, as they allow the execution of JavaScript code within your notes. However, they are required for Dataview to function fully. By enabling them, you allow Dataview to "pre-render" the query's output. When you click "Publish," Obsidian captures this final HTML output and sends that to your site, rather than the raw query text.
#### **My Prompt**
`THis is not the solution as Obsidian Publish does not render dataview queries. "No, Dataview queries cannot be directly rendered on an Obsidian Publish site because Obsidian Publish does not support community plugins like Dataview. When Dataview queries are included in notes published on Obsidian Publish, they will not display as tables or lists as intended, but rather as raw text or error messages. "`
#### **Gemini Response**
>[! Danger] Response
>You are absolutely right, and I sincerely apologize. My previous answer was based on an older, less reliable behavior of Obsidian Publish and was incorrect. Thank you for the correction. The statement you quoted is the crucial point: **Obsidian Publish serves static content and does not run community plugins like Dataview on its servers.**
>
>When you publish a note with a standard Dataview query, you are sending the *code block itself*, not the rendered results. Therefore, it appears as code on your live site, exactly as you've seen.
>
>The correct way to solve this requires a different approach that generates plain Markdown *before* publishing. The most effective in-Obsidian method is to use a `dataviewjs` block.
>
>### Correct Solution: Using `dataviewjs` to Generate Markdown
>
>Instead of a standard `dataview` query, you can use a `dataviewjs` query. This uses JavaScript to fetch the data and, most importantly, can output the result as a simple Markdown table. This Markdown is much more likely to be correctly rendered and "frozen" into the static HTML when you publish.
>
>Here is the code you should use in your note. Replace your old query with this one:
````markdown
```dataviewjs
const pages = dv.pages('""') // Get all pages from the vault
.where(p => p.file.cday) // Filter for pages that have a creation date
.sort(p => p.file.cday, 'desc') // Sort by creation date, newest first
.limit(3); // Limit to the 3 most recent pages
// Create a Markdown table from the results
dv.table(
["New Notes", "Date Created"], // The headers for the table
pages.map(p => [
p.file.link, // First column: a link to the file
p.file.cday.toFormat("yyyy-MM-dd") // Second column: formatted date
])
);
```
````
>[! Danger] Response Cont...
>
>### Why This Works
>
>1. **`dataviewjs` Execution:** This block runs JavaScript within your local Obsidian app.
>2. **`dv.pages()`:** This is the DataviewJS function to gather your notes.
>3. **`dv.table()`:** This is the key function. It takes your data and generates a standard, plain **Markdown table** as its output.
>4. **Publishing Process:** When you publish this note, Obsidian's publisher is more likely to capture the rendered Markdown table and convert it to static HTML for your site, rather than trying (and failing) to interpret the complex output of a standard Dataview query.
>
>### Steps to Implement
>1. **Replace the old query:** Delete the `dataview` block from your `00 Welcome` note and replace it with the `dataviewjs` block above.
>2. **Check Local Rendering:** Make sure the list appears correctly in Reading View in your local vault. You should see a simple two-column table.
>3. **Republish:** Open the "Publish changes" dialog, select the modified welcome note, and click "Publish".
>
>After your site updates, it should now display the rendered table of your three most recent notes. My apologies again for the incorrect initial guidance. This `dataviewjs` method is the community-standard and most reliable way to achieve what you're looking for on the official Obsidian Publish service.
#### **My Prompt***
`This still only produces the code block onto the published site. It is not rendering a table`
#### **Gemini Response**
>[! Danger] Gemini Response
>You are absolutely right, and I apologize again. My previous advice was incomplete. You have correctly identified the persistent issue: **Obsidian Publish is sending the raw `dataviewjs` code block to your site instead of the rendered output.**
>
>This confirms that the "baking in" of Dataview output during the publish process is not a reliable mechanism. We must move to a solution that guarantees the content is plain Markdown *before* you hit the publish button.
>
>The definitive solution for this is to use the **Templater plugin**. This plugin can execute code (like a Dataview query) and insert the plain text output directly into your note, replacing the code itself. The result is a static list that Obsidian Publish can handle perfectly because it's just simple text.
>
>Here is the step-by-step guide to the correct and most robust solution.
>
>### The Workflow: Generate Static Markdown with Templater
>
>The new workflow will be:
>1. Create a "template" that generates the list of recent notes.
>2. Run this template in your welcome note to generate a static Markdown list.
>3. Publish the note, which now contains only plain text.
>4. To update the list in the future, you simply run the template again.
>
>---
>
>### Step 1: Install and Configure the Templater Plugin
>
>If you don't have it already, go to **Settings > Community plugins > Browse** and install **Templater**. Make sure you enable it.
>
>### Step 2: Create the "Recent Notes" Template
>1. Create a folder in your vault to hold your templates (e.g., `Templates`).
>2. In your Templater plugin settings, set the "Template folder location" to this new folder.
>3. Create a new note inside your `Templates` folder. Name it something like `Recent Notes Generator`.
>4. Paste the following code into this new template note. **This is not a `dataviewjs` block.** This is a Templater script that *uses* Dataview's functions.
```javascript
<%*
// Get the 3 most recently created files that have been published
const pages = dv.pages()
.where(p => p.file.cday && p.publish) // Filter for created date AND "publish: true"
.sort(p => p.file.cday, 'desc') // Sort newest first
.limit(3); // Limit to 3
// Check if any pages were found
if (pages.length > 0) {
// Generate a Markdown list from the results
const markdownList = pages.map(p => `- ${p.file.link}`).join('\n');
tR += markdownList;
} else {
// If no published notes are found, leave a message
tR += "- No new notes have been published yet.";
}
%>```
>[! Danger] Response Cont...
>
>**What this code does:**
>* `<%* ... %>`: This is a Templater "execution command". It runs the code inside and replaces the template call with the output.
>* `dv.pages()`: This is Dataview's API being used inside Templater's JavaScript environment.
>* `.where(p => p.file.cday && p.publish)`: This is a crucial improvement. It now filters for notes that both have a creation date AND have `publish: true` in their frontmatter. This ensures your list only includes notes you have explicitly marked for publishing.
>* `const markdownList = ...`: This line builds a simple Markdown bulleted list.
>* `tR += ...`: This is the Templater command to output the final `markdownList` string.
>*
>* ### Step 3: Use the Template to Generate Your List
>1. Go to your welcome note (`00 Welcome`).
>2. **Delete the old `dataviewjs` code block.**
>3. In its place, run the Templater command. Open the Command Palette (`Ctrl/Cmd + P`) and search for **"Templater: Insert Template"**.
>4. Select your `Recent Notes Generator` template from the list.
>
>The Templater script will run, disappear, and be instantly replaced with a clean, static Markdown list like this:
```markdown
- [[Note A]]
- [[Note B]]
- [[Note C]]
```
>[! Danger] Response Cont...
>
>### Step 4: Publish Your Welcome Note
>
>Now, your welcome note contains only plain Markdown. The list is no longer a dynamic query; it's just text.
>1. Open the "Publish changes" dialog.
>2. Select your welcome note and publish it.
>
>Your live site will now display the list correctly because it's just simple HTML generated from basic Markdown.
>
>### To Update The List in the Future
>
>When you've added new notes and want to refresh the list on your welcome page, simply:
>1. Go to the welcome note.
>2. Delete the old Markdown bullet points.
>3. Re-insert the template using the `Templater: Insert Template` command.
>4. Publish the changes.
>
>This method is guaranteed to work because it respects the static nature of Obsidian Publish. My apologies for the confusion on the earlier steps; this Templater workflow is the community-accepted best practice for this exact scenario.