This solution is based on the Butterfly theme for Hexo, for details see Butterfly - Hexo Theme Installation and Configuration

What is PWA

Progressive Web Apps (PWA) are applications built using web platform technologies, but they provide a user experience akin to an app specific to a platform.

Like websites, PWAs can run on multiple platforms and devices with a single code base. Like an app specific to a platform, they can be installed on devices, run offline and in the background, and integrate with the device and other installed apps.

It is a lightweight cross-platform app based on web technology. Compared to traditional apps, it is lighter, easier to install, and more user-friendly. Compared to traditional web, it supports offline operation and has more powerful API support, allowing it to achieve more functions than traditional web.

For more information, refer to:

Install Hexo Plugin

  1. Install the hexo-offline plugin in the project root directory

    1
    pnpm install hexo-offline
  2. Create a hexo-offline.config.cjs file in the project root directory, and add the following content:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    // offline config passed to workbox-build.
    module.exports = {
    globPatterns: ['**/*.{js,html,css,png,jpg,gif,svg,webp,eot,ttf,woff,woff2}'],
    globDirectory: 'public',
    swDest: 'public/service-worker.js',
    maximumFileSizeToCacheInBytes: 10485760, // Maximum file size to cache, in bytes.
    skipWaiting: true,
    clientsClaim: true,
    }

For more configuration options, see hexo-offline official documentation

Create Web App Manifest

Create a manifest.json file in the source/ directory of the project, and add the following content:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"name": "Aghenim Sanctuary",
// App Name
"short_name": "Aghenim Sanctuary",
// App Short Name
"start_url": "/index.html",
"display": "standalone",
"description": "Web & DevOps & More",
// App Description
"orientation": "natural",
"prefer_related_applications": false,
"theme_color": "#000",
// Theme Color
"background_color": "#000",
// Background Color
"icons": [
{
"src": "logo.png",
"sizes": "500x500"
// sizes should match the actual dimensions of the Logo
}
],
"scope": "/"
}

You can also quickly create a manifest.json through Web App Manifest

Warning⚠️: Please modify the configuration as needed, and ensure the correct relative paths for manifest.json and various size logos.

Warning⚠️: JSON does not support comments, please remove comments when pasting this content into the project.

Configure to Enable PWA

  1. Butterfly theme configuration

    Open the _config.butterfly.yml configuration file in the project root directory, and add the following section:

    1
    2
    3
    4
    5
    6
    7
    pwa:
    enable: true // Enable/Disable PWA
    manifest: /img/pwa/manifest.json // Manifest inclusion
    apple_touch_icon: /img/pwa/logo.png // Icon used when installing Web App on Safari on iOS
    favicon_32_32: /img/pwa/logo32-32.png // 32*32 pixel icon
    favicon_16_16: /img/pwa/logo16-16.png // 16*16 pixel icon
    mask_icon: /img/pwa/logo.png // Standard size icon

    See above comments for specific configuration item meanings

    Warning⚠️: Please ensure the correct relative paths for manifest.json and various size logos.

Run

After correctly completing the above process, opening the website will now allow you to install the App:

1704782626684

PWA Web App access effect is as follows:

1704783579624

1704783309101