Skip to content

Commit

Permalink
fix errors and add start script for package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHadiAhmadi committed Dec 13, 2024
1 parent 05cd7ca commit 3dbb46c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion bin/tailcms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { readdir, writeFile, mkdir } from 'fs/promises';
import path from 'path';
import { createApp } from '../src/app.js';
import { createFileDb } from 'svelite-html/db';
import { createFileDb, createMemoryDb } from 'svelite-html/db';
import { existsSync, mkdirSync } from 'fs';
import { chdir } from 'process';

Expand Down Expand Up @@ -112,6 +112,8 @@ async function runDev(cwd) {
if (config.db.type === 'file') {
const { type, ...rest } = config.db;
db = createFileDb(rest);
} else {
db = createMemoryDb({})
}

const port = process.env.TAILCMS_PORT ?? 3000;
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ const {PORT = 3000} = process.env

const db = createFileDb({path: './data.json'})

console.log({db})

createApp({functions, db}).listen(PORT, () => console.log('app started on http://localhost:' + PORT))
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"#helpers": "./src/helpers.js"
},
"scripts": {
"start": "node bin/tailcms.js dev",
"dev": "node bin/tailcms.js dev",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
10 changes: 6 additions & 4 deletions public/js/setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { setFormValue } from "/js/form.js";
// import { setFormValue } from "/js/helpers.js";
// import { Form } from "/js/form.js";
// import { FileUploader } from './fileuploader.js'

// Form(document.querySelector('[data-form]'))

// FileUploader(document.querySelector('[data-file-label]'))

document.querySelector('[data-form]').action = '/api/setup'
document.querySelector('[data-form]').method = 'POST'

setFormValue(document.querySelector('[data-form]'), {
password: 'Passw0rd!',
})
// setFormValue(document.querySelector('[data-form]'), {
// password: 'Passw0rd!',
// })
1 change: 1 addition & 0 deletions services/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createFileDb, createMongoDb } from 'svelite-html/db'
// const db = createMongoDb({uri: 'mongodb://127.0.0.1:27017', db:'SiteBuilder'})

export function setDb(value) {
console.log('setdb', value)
db = value
}

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
await db('pages').insert(body)

return {
redirect: '/admin?view=pages.edit&slug=' + encodeURIComponent(body.slug)
redirect: '/admin?view=pages.edit&id=' + body.id
}
},
async load(body) {
Expand Down
4 changes: 4 additions & 0 deletions src/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default {
{{{head}}}
{{/eq}}
{{#eq mode 'setup'}}
{{{head}}}
{{/eq}}
<link rel="icon" href="/files/{{settings.favicon}}.svg" type="image/svg+xml">
<title>{{seo.title}}</title>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function PageEditorPage({url, query, view, permissions}) {
}}) : ''}
${page?.name ?? 'Untitled'}
${view === 'iframe' ? `` : `
<a target="_blank" href="${slug}" data-button data-button-color="primary" data-button-ghost>
<a target="_blank" href="${page.slug}" data-button data-button-color="primary" data-button-ghost>
Preview
<svg data-icon xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M10.75 1a.75.75 0 0 0 0 1.5h1.69L8.22 6.72a.75.75 0 0 0 1.06 1.06l4.22-4.22v1.69a.75.75 0 0 0 1.5 0V1zM2.5 4v9a.5.5 0 0 0 .5.5h9a.5.5 0 0 0 .5-.5V8.75a.75.75 0 0 1 1.5 0V13a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h4.25a.75.75 0 0 1 0 1.5H3a.5.5 0 0 0-.5.5" clip-rule="evenodd"/></svg>
</a>
Expand Down
1 change: 1 addition & 0 deletions src/pages/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { File, Form, Input, Select } from '#components'
export function SetupPage({templates}) {
return layouts.default({
title: 'Setup CMS',
mode: 'setup',
head: [
'<link rel="stylesheet" href="/pages/setup/style.css">',
'<script type="module" src="/js/setup.js"></script>'
Expand Down

0 comments on commit 3dbb46c

Please sign in to comment.