/**
 * Parse front page HTML from API (string or object) into a plain object.
 */
export function parsePageHtml(html) {
    if (!html) {
        return { sections: [] }
    }

    if (typeof html === 'object') {
        return html
    }

    if (typeof html === 'string') {
        try {
            const parsed = JSON.parse(html)
            return parsed && typeof parsed === 'object' ? parsed : { sections: [] }
        } catch (e) {
            return { sections: [] }
        }
    }

    return { sections: [] }
}
