file-list.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const topFileTypes = ['bbl', 'gls', 'ind']
  2. const ignoreFiles = ['output.fls', 'output.fdb_latexmk']
  3. export const buildFileList = (outputFiles, clsiServerId) => {
  4. const files = { top: [], other: [] }
  5. if (outputFiles) {
  6. const params = new URLSearchParams()
  7. if (clsiServerId) {
  8. params.set('clsiserverid', clsiServerId)
  9. }
  10. const queryString = params.toString()
  11. const allFiles = []
  12. // filter out ignored files and set some properties
  13. for (const file of outputFiles.values()) {
  14. if (!ignoreFiles.includes(file.path)) {
  15. file.main = file.path.startsWith('output.')
  16. if (queryString.length) {
  17. file.url += `?${queryString}`
  18. }
  19. allFiles.push(file)
  20. }
  21. }
  22. // sort main files first, then alphabetical
  23. allFiles.sort((a, b) => {
  24. if (a.main && !b.main) {
  25. return a
  26. }
  27. if (b.main && !a.main) {
  28. return b
  29. }
  30. return a.path.localeCompare(b.path)
  31. })
  32. // group files into "top" and "other"
  33. for (const file of allFiles) {
  34. if (topFileTypes.includes(file.type)) {
  35. files.top.push(file)
  36. } else if (!(file.type === 'pdf' && file.main === true)) {
  37. files.other.push(file)
  38. }
  39. }
  40. }
  41. return files
  42. }