Expand search on Dawn to include pages?

Hi again (@minimaluminium, looking at you :smile:). Getting very close to being done tweaking on the Dawn theme, but now hoping to figure out a way of expanding search results to include pages as well as posts. Any quick tips?

Thanks so much in advance!

One more, totally unrelated question @minimaluminium… where did you get the SVG social icons in the footer? Looking to add a couple there if I can find some that match well.

Hello there! I think this might not be a quick thing to be changed. To include pages in the search results, an API call to the pages resource /content/pages must be made. Something like this could be added.

var pageUrl =
        siteUrl +
        '/ghost/api/v3/content/pages/?key=' +
        gh_search_key +
        '&limit=all&fields=id,title,url,updated_at,visibility&order=updated_at%20desc';

pageUrl += includeContent ? '&formats=plaintext' : '';

And make 2 separate calls and combine the results.

var postCall = $.get(url);
var pageCall = $.get(pageUrl);

$.when(postCall, pageCall).then(function (postData, pageData) {
    var data = {posts: postData[0]['posts'].concat(pageData[0]['pages'])};

    // And do the rest (setting the index, update the localStorage etc...)
});

Maybe this could be an option in the theme instead of adding heavy customization.

And for the icons, we used Material Design icons. https://materialdesignicons.com/

1 Like

Having that as an option would be awesome. I’ll hold off tweaking it for now, keep me posted! :slight_smile:

Thanks so much as always for the tips.