@@ -4,17 +4,38 @@ import { matchCodeBlocks } from '../utils/md-statistics';
44import { pie_base64 } from '../utils/chart' ;
55import { countLines } from '../utils/common' ;
66
7+ const langMap = {
8+ javascript : [ 'js' , 'javascript' , 'JavaScript' , 'jsx' ] ,
9+ cpp : [ 'c++' , 'cpp' , 'CPP' ] ,
10+ typescript : [ 'ts' , 'typescript' , 'TypeScript' , 'tsx' ] ,
11+ python : [ 'py' , 'python' , 'Python' ] ,
12+ java : [ 'java' , 'Java' ] ,
13+ go : [ 'go' , 'Go' , 'golang' ] ,
14+ rust : [ 'rs' , 'rust' , 'Rust' ] ,
15+ html : [ 'html' , 'HTML' , 'htm' ] ,
16+ css : [ 'css' , 'CSS' , 'scss' , 'Sass' , 'sass' , 'less' , 'Less' ] ,
17+ shell : [ 'sh' , 'bash' , 'Shell' , 'zsh' ] ,
18+ text : [ 'text' , 'Text' , 'txt' , 'Txt' , 'plaintext' , 'Plaintext' , 'in' , 'out' ] ,
19+ }
20+
21+ const getStdLang = ( lang : string ) => {
22+ for ( const [ stdLang , variants ] of Object . entries ( langMap ) ) {
23+ if ( variants . includes ( lang ) ) {
24+ return stdLang ;
25+ }
26+ }
27+ return lang ;
28+ }
29+
730export default {
831 async load ( ) {
9- const count = new EasyMap < string , number > ( { defaultValue : 0 } ) ;
32+ const count = new EasyMap < string , number > ( ) ;
1033 const proxy = count . createProxy ( p => {
1134 return typeof p === 'string' ? p : p . toString ( ) ;
12- } ) ;
35+ } , 0 ) ;
1336 loadFiles ( '_posts/**/*.md' , ( content ) => {
1437 matchCodeBlocks ( content ) . forEach ( ( { language, code} ) => {
15- if ( language === 'c++' ) language = 'cpp' ;
16- if ( language === 'in' || language === 'out' ) language = 'text' ;
17- proxy [ language ] += countLines ( code ) ;
38+ proxy [ getStdLang ( language ) ] += countLines ( code ) ;
1839 } ) ;
1940 } ) ;
2041 const pieData = {
0 commit comments