Apple Notes 是我的 CMS

介绍您可能已经了解过这个表情包以及 apple notes 的优越性。
那么,如果您可以将其用作 cms 来管理博客内容呢?这就是我想在我的“今天我学到了”网站上尝试的。这是最终结果 https://til.julienc.me查询苹果笔记

介绍

您可能已经了解过这个表情包以及 apple notes 的优越性。
Apple Notes 是我的 CMS
那么,如果您可以将其用作 cms 来管理博客内容呢?这就是我想在我的“今天我学到了”网站上尝试的。这是最终结果 https://til.julienc.me

apple notes 是我的 cms

查询苹果笔记

我们需要一种从 apple notes 中获取笔记的方法。为此,我们将使用 anyquery,它是一个 sql 数据库,可以查询几乎任何内容,包括 apple notes。

  1. 在 https://anyquery.dev/docs/#installation 安装 anyquery
  2. 安装apple notes插件:anyquery install notes
  3. 使用 sql 查询我们的笔记并将其保存为 json(在我的例子中,我的笔记位于文件夹 til 中)

    anyquery -q "select name, html_body, modification_date 
    from notes_items where folder = 'til';" --json > notes.json 
    

    登录后复制

您现在有一个文件notes.json,其中包含对象数组中的所有笔记。每个对象都有三个属性:

  • 笔记名称(name)
  • 最后修改时间(modification_date)
  • html 中的正文注释 (html_body)

例如:

[
    {
        "name": "example",
        "modification_date": "2024-08-11t00:00:00z",
        "html_body": "<h1>example</h1><p>this is an example</p>"
    }
]

登录后复制

我们的最后一个任务是将网站连接到它

连接网站

就我个人而言,我使用 astro.js。我们的第一个任务是为每个条目生成静态路径。
为此,我可以从“../../notes.json”导入注释;并将其传递给导出函数 getstaticpaths()。我还使用 slugify 函数来确保生成的 url 有效。

// [...blog].astro
import notes from "../../notes.json";

function slugify(string: string) {
    return string
        .tolowercase()
        .replace(/s+/g, "-")
        .replace(/[^a-z0-9-]/g, "");
}

export function getstaticpaths() {
    return notes.map((note) => {
        return {
            params: {
                blog: slugify(note.name),
            },
        };
    });
}

const { blog } = astro.params;
const note = notes.find((note) => slugify(note.name) === blog);

登录后复制

生成路径后,我们需要编写一些 css 来匹配 apple notes 样式:

article.notes {
            color: #454545;
            font-size: 0.9rem;
            font-style: normal;
            font-weight: 400;
            line-height: normal;
            letter-spacing: -0.015rem;
        }

article.notes > p:first-child > h1 {
        color: #de9807;
        margin-bottom: 0.5rem;
}

... truncated (retrieve the full CSS in the repository at src/styles.css)

登录后复制

我们现在完成了!

结论

恭喜,您现在正在使用 apple notes 作为 cms。它是一款功能强大的协作式 cms,仅受您的 icloud 存储限制限制。您可以添加图像、表格、格式化文本、代码等
以下是格式选项的示例:
https://til.julienc.me/example-of-capability
Apple Notes 是我的 CMS

您可以通过执行以下操作将您自己的博客从 apple notes 部署到 vercel:

  • 克隆存储库 git clone https://github.com/julien040/apple-notes-cms
  • 运行 npm install 或 pnpm install
  • 运行 chmod u+x deploy.sh
  • 运行 vercel 来初始化并连接项目
  • 运行 ./deploy.sh 构建项目并将其推送到 vercel

链接

源代码:https://github.com/julien040/apple-notes-cms
结果:https://til.julienc.me/

以上就是Apple Notes 是我的 CMS的详细内容,更多请关注叮当号网其它相关文章!

文章来自互联网,只做分享使用。发布者:叮当,转转请注明出处:https://www.dingdanghao.com/article/717768.html

(0)
上一篇 2024-08-13 10:12
下一篇 2024-08-13 10:12

相关推荐

联系我们

在线咨询: QQ交谈

邮件:442814395@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信公众号