Skip to content

Commit c008e10

Browse files
author
Ajit Kumar
committed
feat(open graph support for plugins)
1 parent 668b04f commit c008e10

14 files changed

+148
-112
lines changed

.vscode/server.crt

-16
This file was deleted.

.vscode/server.key

-18
This file was deleted.

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@
7171
"smali",
7272
"smtppro",
7373
"zenburn"
74-
]
74+
],
75+
"[handlebars]": {
76+
"editor.defaultFormatter": "vscode.html-language-features"
77+
}
7578
}

client/pages/publishPlugin/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import AjaxForm from 'components/ajaxForm';
77
import Router from 'lib/Router';
88
import Ref from 'html-tag-js/ref';
9+
import alert from 'components/dialogs/alert';
910

1011
export default async function PublishPlugin({ mode = 'publish', id }) {
1112
const user = await getLoggedInUser();
@@ -107,7 +108,7 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
107108
return;
108109
}
109110

110-
successText.value = 'Plugin published successfully.';
111+
alert('Success', 'Plugin published successfully.');
111112
Router.loadUrl(`/plugin/${pluginId.value}`);
112113
}
113114

File renamed without changes.

dev/handlebars-loader.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Handlebars from 'handlebars';
2+
3+
export default (source) => {
4+
const template = Handlebars.precompile(source, {
5+
destName: 'index.html',
6+
knownHelpers: ['if'],
7+
});
8+
return `
9+
import Handlebars from 'handlebars/runtime';
10+
export default Handlebars.template(${template});
11+
`;
12+
};

tools/start-dev.js renamed to dev/start-dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { exec } = require('child_process');
33

44
const inspect = process.argv.includes('--inspect');
5-
const configProcess = exec('node ./tools/config.js d', processHandler);
5+
const configProcess = exec('node ./dev/config.js d', processHandler);
66
configProcess.on('exit', build);
77

88
function build(watch) {

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"style-loader": "^4.0.0",
3434
"terser-webpack-plugin": "^5.3.11",
3535
"url-loader": "^4.1.1",
36-
"webpack": "5.97.1",
36+
"webpack": "5.98.0",
3737
"webpack-bundle-analyzer": "^4.10.2",
3838
"webpack-cli": "6.0.1"
3939
},
@@ -50,17 +50,19 @@
5050
"express-fileupload": "^1.5.1",
5151
"github-buttons": "^2.29.1",
5252
"googleapis": "^144.0.0",
53+
"handlebars": "^4.7.8",
5354
"html-tag-js": "^1.8.2",
5455
"jszip": "^3.10.1",
56+
"markdown-to-txt": "^2.0.1",
5557
"marked": "^15.0.6",
5658
"moment": "^2.30.1",
5759
"nodemailer": "^6.10.0",
5860
"sqlite3": "^5.1.7"
5961
},
6062
"scripts": {
61-
"config-build": "node ./tools/config",
63+
"config-build": "node ./dev/config",
6264
"build-release": "yarn config-build p && webpack --mode production",
63-
"start-dev": "node ./tools/start-dev",
65+
"start-dev": "node ./dev/start-dev",
6466
"upgrade-meta": "node ./server/upgradeMeta",
6567
"download": "node ./server/reportsCli",
6668
"start": "node ./server/main"

server/defaultOg.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"title": "Acode - powerful code editor",
3+
"description": "Acode is a code editor for android. It is a full featured code editor with syntax highlighting, code completion, snippets, code refactoring, code analysis, and much more.",
4+
"icon": "og-image.png",
5+
"url": "path",
6+
"icon_alt": "Acode logo",
7+
"site_name": "Acode"
8+
}

server/index.hbs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<html lang="en">
2+
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<script src="/main.min.js"></script>
7+
<script chatbot_id="6620db2dde66b9a82e9ff3f9" src="https://app.thinkstack.ai/bot/thinkstackai-loader.min.js"></script>
8+
<link rel="stylesheet" href="/main.css" />
9+
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
10+
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
11+
<link rel="icon" href="/favicon-16x16.png" type="image/png" />
12+
<link rel="manifest" href="/manifest.json" />
13+
<link rel="preconnect" href="https://fonts.googleapis.com" />
14+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
15+
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet" />
16+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" type="image/png" />
17+
<title>Acode - Code editor for android</title>
18+
19+
<!-- og meta tags -->
20+
<meta property="og:title" content="{{title}}" />
21+
<meta property="og:description" content="{{description}}" />
22+
<meta property="og:image" content="https://acode.app/{{icon}}" />
23+
<meta property="og:image:width" content="400" />
24+
<meta property="og:image:height" content="200" />
25+
<meta property="og:image:alt" content="{{icon_alt}}" />
26+
<meta property="og:url" content="https://acode.app/{{path}}" />
27+
<meta property="og:type" content="website" />
28+
<meta property="og:site_name" content="{{site_name}}" />
29+
<meta property="og:locale" content="en_US" />
30+
<!-- Google tag (gtag.js) -->
31+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YX6J9WVCDP"></script>
32+
<script>
33+
window.dataLayer = window.dataLayer || [];
34+
function gtag() {
35+
dataLayer.push(arguments);
36+
}
37+
gtag('js', new Date());
38+
39+
gtag('config', 'G-YX6J9WVCDP');
40+
</script>
41+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5911839694379275"
42+
crossorigin="anonymous"></script>
43+
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
44+
</head>
45+
46+
<body>
47+
<noscript>Please enable javascript to view this page.</noscript>
48+
<div id="app"></div>
49+
</body>
50+
51+
</html>

server/index.html

-68
This file was deleted.

server/main.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const path = require('path');
55
const express = require('express');
66
const cookieParser = require('cookie-parser');
77
const fileUpload = require('express-fileupload');
8+
const Handlebars = require('handlebars');
9+
const markdownToText = require('markdown-to-txt');
10+
const defaultOg = require('./defaultOg.json');
11+
const Plugin = require('./entities/plugin');
812

913
const apis = require('./routes/apis');
1014
const setAuth = require('./gapis');
@@ -94,7 +98,38 @@ async function main() {
9498
res.status(404).send({ error: 'Plugin not found' });
9599
});
96100

101+
app.get('/plugin/:id', async (req, res, next) => {
102+
try {
103+
const [plugin] = await Plugin.get([Plugin.ID, req.params.id]);
104+
if (!plugin) {
105+
next();
106+
return;
107+
}
108+
109+
const template = path.resolve(__dirname, './index.hbs');
110+
const source = fs.readFileSync(template, 'utf8');
111+
const templateScript = Handlebars.compile(source);
112+
113+
res.header('Content-Type', 'text/html;charset=utf-8');
114+
res.send(templateScript({
115+
title: `${plugin.name} - Acode`,
116+
description: markdownToText.default(plugin.description),
117+
icon: `plugin-icon/${plugin.id}`,
118+
url: `plugin/${plugin.id}`,
119+
icon_alt: `${plugin.name} icon`,
120+
site_name: `Acode - ${plugin.name}`,
121+
}));
122+
} catch (error) {
123+
next();
124+
}
125+
});
126+
97127
app.get('*', (req, res) => {
98-
res.sendFile(path.resolve(__dirname, './index.html'));
128+
const template = path.resolve(__dirname, './index.hbs');
129+
const source = fs.readFileSync(template, 'utf8');
130+
const templateScript = Handlebars.compile(source);
131+
132+
res.header('Content-Type', 'text/html;charset=utf-8');
133+
res.send(templateScript(defaultOg));
99134
});
100135
}

webpack.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = (env, options) => {
4949

5050
const rules = [
5151
{
52-
test: /\.(hbs|md)$/,
52+
test: /\.md$/,
5353
use: ['raw-loader'],
5454
},
5555
{
@@ -60,6 +60,10 @@ module.exports = (env, options) => {
6060
'sass-loader',
6161
],
6262
},
63+
{
64+
test: /\.hbs$/,
65+
use: ['./dev/handlebars-loader.js'],
66+
},
6367
{
6468
test: /\.jsx?$/,
6569
exclude: /(node_modules)/,

yarn.lock

+24-2
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,18 @@ gzip-size@^6.0.0:
36243624
dependencies:
36253625
duplexer "^0.1.2"
36263626

3627+
handlebars@^4.7.8:
3628+
version "4.7.8"
3629+
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.8.tgz#41c42c18b1be2365439188c77c6afae71c0cd9e9"
3630+
integrity sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==
3631+
dependencies:
3632+
minimist "^1.2.5"
3633+
neo-async "^2.6.2"
3634+
source-map "^0.6.1"
3635+
wordwrap "^1.0.0"
3636+
optionalDependencies:
3637+
uglify-js "^3.1.4"
3638+
36273639
has-ansi@^2.0.0:
36283640
version "2.0.0"
36293641
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
@@ -4708,7 +4720,7 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
47084720
dependencies:
47094721
brace-expansion "^1.1.7"
47104722

4711-
minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.6:
4723+
minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6:
47124724
version "1.2.8"
47134725
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
47144726
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
@@ -6134,7 +6146,7 @@ source-map@^0.5.6, source-map@^0.5.7:
61346146
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
61356147
integrity sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==
61366148

6137-
source-map@^0.6.0:
6149+
source-map@^0.6.0, source-map@^0.6.1:
61386150
version "0.6.1"
61396151
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
61406152
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@@ -6574,6 +6586,11 @@ typed-array-length@^1.0.7:
65746586
possible-typed-array-names "^1.0.0"
65756587
reflect.getprototypeof "^1.0.6"
65766588

6589+
uglify-js@^3.1.4:
6590+
version "3.19.3"
6591+
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.19.3.tgz#82315e9bbc6f2b25888858acd1fff8441035b77f"
6592+
integrity sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==
6593+
65776594
unbox-primitive@^1.1.0:
65786595
version "1.1.0"
65796596
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.1.0.tgz#8d9d2c9edeea8460c7f35033a88867944934d1e2"
@@ -6917,6 +6934,11 @@ word-wrap@^1.2.5:
69176934
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
69186935
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
69196936

6937+
wordwrap@^1.0.0:
6938+
version "1.0.0"
6939+
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
6940+
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
6941+
69206942
wrappy@1:
69216943
version "1.0.2"
69226944
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

0 commit comments

Comments
 (0)