Skip to content

Commit

Permalink
Added better auto detect for title via content
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFun123 committed Oct 10, 2023
1 parent 6cffead commit 6cbc9d2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
13 changes: 9 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"babel-polyfill": "^6.26.0",
"core-js": "^3.6.5",
"highlight.js": "^11.9.0",
"markdown-it": "^12.0.4",
"petrel": "^1.0.7",
"portal-vue": "^2.1.7",
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/assets/data/langReplacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ export default {
vue: 'xml',
yml: 'yaml',
py: 'python',
py3: 'python',
py2: 'python',
css: 'scss',
sass: 'yaml',
cs: 'csharp',
env: 'properties',
txt: "text",
h: "c",
ino: "c"
ino: "c",
}
57 changes: 57 additions & 0 deletions frontend/src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,63 @@ export function estimateTitle(contents) {
return `data.json`
}

try {
if (contents.length < 10000) {
const auto = hljs.highlightAuto(contents)

const languages = {
javascript: 'script.js',
typescript: 'script.ts',
coffeescript: 'script.js',
java: 'Program.java',
groovy: 'Program.groovy',
kotlin: 'Program.kt',
'php-template': 'component.php',
php: 'index.php',
lua: 'extension.lua',
r: 'file.r',
ini: 'config.ini',
toml: 'config.toml',
diff: 'changes.diff',
properties: '.env',
json: 'data.json',
scss: 'styles.scss',
css: 'styles.css',
less: 'styles.less',
shell: 'script.sh',
bash: 'script.bash',
apache: '.htaccess',
rust: 'program.rs',
yaml: 'data.yml',
'python-repl': 'app.py',
python: 'app.py',
dockerfile: 'Dockerfile',
sql: 'db.sql',
markdown: 'document.md',
vbscript: 'program.vbs',
swift: 'app.swift',
cpp: 'app.cpp',
c: 'app.c',
csharp: 'App.cs',
http: 'request.http',
perl: 'app.pl',
nginx: 'config.nginx',
objectivec: 'program.m',
go: 'app.go',
dart: 'component.dart',
}

if (auto.language in languages) {
return languages[auto.language]
}
if (auto.secondBest?.language && auto.secondBest.language in languages) {
return languages[auto.secondBest?.language]
}
}
} catch (e) {
//
}

return ''
}

Expand Down
1 change: 0 additions & 1 deletion frontend/src/test.js

This file was deleted.

5 changes: 5 additions & 0 deletions frontend/src/views/Paste.vue
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ h1 {
* {
font-family: "DM Sans";
}
pre, pre * {
font-family: "DM Mono";
}
h1, h2, h3 {
font-family: "DM Serif Text";
}
Expand Down

0 comments on commit 6cbc9d2

Please sign in to comment.