diff --git a/public/assets/posts/hello-world.json b/public/assets/posts/hello-world.json
new file mode 100644
index 0000000..75fd470
--- /dev/null
+++ b/public/assets/posts/hello-world.json
@@ -0,0 +1,8 @@
+{
+ "postTitle": "Hello World!",
+ "timestamp": "1654062776",
+ "editedTimestamp": "",
+ "postContent": "Welcome to my humble blog! This blog is hosted using a blog platform loosely based on my [ngx-dumblog](http:\/\/github.com\/pedroCX486\/ngx-dumblog) project. My intent is to make this look more and more retro with time.\r\n \r\nAnd before you ask, it's availabe [here](http:\/\/git.pedrocx486.club\/pedrocx486\/ngx-retroblog).\r\n \r\nFor more info (maybe), check [The Club](https:\/\/pedrocx486.club)!",
+ "filename": "hello-world",
+ "draft": false
+}
diff --git a/src/App.vue b/src/App.vue
index aeda89d..44482b1 100755
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,133 +1,104 @@
@@ -167,6 +138,7 @@ button {
width: 100%;
height: 85vh;
position: relative;
+ margin-bottom: -1.3rem;
}
.editor-area {
@@ -198,16 +170,22 @@ button {
.preview-title {
margin-top: 0;
+ border-bottom: solid 1px;
}
-.preview>* {
+.preview > * {
max-width: 50vw;
line-break: normal;
}
+.preview > * p {
+ padding: 0.2rem;
+}
+
@media only screen and (hover: none) {
.wrapper {
flex-direction: column;
+ margin-bottom: unset !important;
}
.preview {
diff --git a/src/file-manager.service.ts b/src/file-manager.service.ts
new file mode 100644
index 0000000..ea54b4d
--- /dev/null
+++ b/src/file-manager.service.ts
@@ -0,0 +1,29 @@
+export const parseFilename = (titleToFilename: string): string => {
+ if (!titleToFilename) {
+ return 'None yet.'
+ }
+
+ titleToFilename = titleToFilename.replace(/[^a-zA-Z0-9_]+/gi, '-').toLowerCase();
+
+ while (titleToFilename.endsWith('-')) {
+ titleToFilename = titleToFilename.slice(0, -1);
+ }
+
+ if (titleToFilename.length > 50) { // Limit filename size
+ titleToFilename = titleToFilename.substring(0, 50);
+
+ if (titleToFilename.includes('-')) {
+ titleToFilename = titleToFilename.substring(0, Math.min(titleToFilename.length, titleToFilename.lastIndexOf('-'))); // Re-trim to avoid cutting a word in half.
+ }
+ }
+
+ return titleToFilename + '.json';
+}
+
+export const downloadFile = (postObj: any, fileName: string, archiveFile?: boolean): void => {
+ const blob = new Blob([JSON.stringify(postObj, null, 2)], { type: 'text/plain;charset=utf-8;' });
+ const a = document.createElement('a');
+ a.setAttribute('download', archiveFile ? 'archive.json' : fileName);
+ a.setAttribute('href', window.URL.createObjectURL(blob));
+ a.click();
+}
\ No newline at end of file
diff --git a/src/axios.provider.ts b/src/http-helper.service.ts
similarity index 66%
rename from src/axios.provider.ts
rename to src/http-helper.service.ts
index 3caa08b..0707b03 100644
--- a/src/axios.provider.ts
+++ b/src/http-helper.service.ts
@@ -1,9 +1,8 @@
import axios from 'axios';
+import { Archive, Post } from './types';
const httpService = axios.create({
headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
'Cache-Control': 'no-cache',
'Pragma': 'no-cache',
'Expires': '0',
@@ -20,13 +19,13 @@ httpService.interceptors.response.use(
export async function getArchive(baseUrl: string) {
- return await httpService.get(`https://${baseUrl}/assets/posts/archive.json`).then((res: any) => {
+ return await httpService.get(`https://${baseUrl}/assets/posts/archive.json`).then((res) => {
return res.data;
});
}
export async function getPost(baseUrl: string, post: string) {
- return await httpService.get(`https://${baseUrl}/assets/posts/${post}.json`).then((res: any) => {
+ return await httpService.get(`http://${baseUrl}/assets/posts/${post}.json`).then((res) => {
return res.data;
});
}
\ No newline at end of file
diff --git a/src/post-utilities.service.ts b/src/post-utilities.service.ts
new file mode 100644
index 0000000..47b90ec
--- /dev/null
+++ b/src/post-utilities.service.ts
@@ -0,0 +1,30 @@
+export const generateTimestamp = (): string => {
+ return Math.round((new Date()).getTime() / 1000).toString();
+}
+
+export const parseTimestampToUTC = (unixTimestamp: string): string => {
+ if (!unixTimestamp) {
+ return ''
+ }
+
+ return new Date(Number(unixTimestamp) * 1000).toUTCString();
+}
+
+export const generatePostObj = (
+ postTitle: string,
+ timestamp: string,
+ postContent: string,
+ filename: string,
+ draft: boolean,
+ isEdit: boolean,
+ editedTimestamp: string
+): Object => {
+ return {
+ postTitle,
+ timestamp: draft ? '' : timestamp,
+ editedTimestamp: draft ? '' : (isEdit ? editedTimestamp : ''),
+ postContent,
+ filename,
+ draft
+ }
+}
\ No newline at end of file
diff --git a/src/types.ts b/src/types.ts
new file mode 100644
index 0000000..8546c1c
--- /dev/null
+++ b/src/types.ts
@@ -0,0 +1,14 @@
+export type Post = {
+ postTitle: string,
+ timestamp: string,
+ editedTimestamp: string,
+ postContent: string,
+ filename: string,
+ draft: boolean
+}
+
+export type Archive = {
+ postTitle: string,
+ timestamp: string,
+ filename: string
+}
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index bcc4abd..a32ea98 100755
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -11,7 +11,8 @@
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
- "skipLibCheck": true
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]