Obsidian DataviewJs

Related to:: Obsidian

Good examples Dataview: reuse DQL queries? - Plugins ideas - Obsidian Forum

example test error

const defaultFormat = 'YYYY-MM-DD';
const format = app['internalPlugins']['plugins']['daily-notes']['instance']['options']['format'] || defaultFormat;

const dailyNotesRegexp = new RegExp(format.replace(/\w/g, '\\d')) || defaultDailyPageRegexp; 

function isDailyNote(page) {
	const path = page.file.path;
	if (!path.startsWith(dv.current().file.folder)) return false;
	
	const filename = page.file.name;
	return filename.match(dailyNotesRegexp)
}


//filter dailyPages and sort it
const dailyPagesSorted = dv.pages()
	.filter(isDailyNote)
		.sort(page => page.file.name)


const curPageInd = dailyPagesSorted
	.findIndex((page, ind) => (page.file.path === this.currentFilePath));

	

const prevPage = curPageInd === 0 ? null : dailyPagesSorted[curPageInd - 1].file;


const nextPage = curPageInd === (dailyPagesSorted.length - 1) ? null : dailyPagesSorted[curPageInd + 1].file;
	
const options = [
	{
		selector: 'a.prev-daily',
		path: prevPage?.path,
		text: prevPage !== null ? `< ${prevPage.name}` : ''
	},
	{
		selector: 'a.next-daily',
		path: nextPage?.path,
		text: nextPage !== null ? `${nextPage.name} >` : ''
	},
];

//use interval to catch moment when links are loaded, btw document.onload not working here
const checkInterval = setInterval(() => {
	options.forEach(({selector, path, text}) => {
		const aEl = document.querySelector(selector);
		
		if (!path || !aEl) return;
		
		//once created links, clear interval
		clearInterval(checkInterval)

		aEl.innerText = text;
		aEl.href = path;
		aEl.classList.add('ready');
		//sometimes Obsidian marks link as unresolved for some reason
		aEl.classList.remove('is-unresolved');
	})
}, 100)


const styles = `
.breadcrumbs-wrapper {
	display: flex; 
	justify-content: space-between;
	margin-top: 50px;
}

.ready.elegant-btn {
	color: black;
	text-decoration: none;
	font-size: 14px;
	padding: 4px 22px;
	border: 2px solid black;
	display: flex;
	justify-content: center;
	background-color: transparent;
	box-shadow: 11px 11px 0px 0px black;
	transition: all 0.2s ease;
}

.ready.elegant-btn:hover {
	box-shadow: 0px 0px 0px 0px black;
}
`

var styleSheet = document.createElement("style")
styleSheet.type = "text/css"
styleSheet.innerText = styles
document.head.appendChild(styleSheet) 

add to js file and use dv.view